﻿namespace BEGDC.CC.Web.UserControls.CV
{
	using System;
	using System.Data;
	using System.Collections;
	using System.Drawing;
	using System.Web;
	using System.Web.UI.WebControls;
	using System.Web.UI.HtmlControls;
	using System.Text;

	using BEGDC.CC.BL.CCFlow.CV;
	using BEGDC.CC.BL.CCFlow.CR;
	using BEGDC.CC.Entity;
	using BEGDC.CC.BL.Workflow;
	using BEGDC.CC.BL.Common;
	using BEGDC.CC.BL.Common.Query;
	using BEGDC.CC.BL.UserManagement;
	using BEGDC.Utility.Castle;

	/// <summary>
	///	Summary description for Apply.
	/// </summary>
	public class CVReadOnlyForm : BaseCV
	{
		#region ui control definition
		protected BEGDC.CC.Web.UserControls.Export ctrlExport;
		protected System.Web.UI.WebControls.Label Lb_CISWarning;
		protected System.Web.UI.WebControls.Label lbTitle;
		protected System.Web.UI.WebControls.ImageButton btnSave;
		protected System.Web.UI.WebControls.ImageButton btnSubmit;
		protected System.Web.UI.WebControls.ImageButton btnReply;
		protected System.Web.UI.WebControls.RadioButtonList rbSomeoneElse;
		protected System.Web.UI.WebControls.TextBox tbSomeoneEmail;
		protected System.Web.UI.WebControls.TextBox tbCustomerName;
		protected System.Web.UI.WebControls.RadioButtonList rbIsFCPA;
		protected System.Web.UI.WebControls.TextBox tbCustomerCountry;
		protected System.Web.UI.WebControls.RadioButtonList rbReviewGuideLine;
		protected System.Web.UI.WebControls.TextBox tbOtherLocation;
		protected System.Web.UI.WebControls.TextBox tbOtherCountry;
		//		protected System.Web.UI.WebControls.TextBox tbGuestNumber;
		protected System.Web.UI.WebControls.TextBox tbVisitObjectives;
		protected System.Web.UI.WebControls.CheckBoxList cblPreferredLocation;
		protected System.Web.UI.WebControls.TextBox tbPotentialRevenue;
		protected System.Web.UI.WebControls.DropDownList ddlPotentialRevenueTime;
		protected System.Web.UI.WebControls.DropDownList ddlSaleStage;
		protected System.Web.UI.WebControls.RadioButtonList rbOutStandingRFP;
		protected System.Web.UI.WebControls.TextBox tbSensitiveIssues;
		protected System.Web.UI.WebControls.TextBox tbKeyMessage;
		protected System.Web.UI.WebControls.TextBox tbCompanyProfile;
		protected System.Web.UI.WebControls.DropDownList ddlAccountType;
		protected System.Web.UI.WebControls.TextBox tbProposalNo;
		protected System.Web.UI.WebControls.RadioButtonList rbSalesContract;
		protected System.Web.UI.WebControls.RadioButtonList rbSalesContractSigned;
		protected System.Web.UI.WebControls.RadioButtonList rbIsSensitiveIssue;
		//		protected System.Web.UI.WebControls.TextBox tbContractDate;
		//		protected System.Web.UI.WebControls.TextBox tbContractNo;
		//		protected System.Web.UI.WebControls.TextBox tbContractProducts;
		//		protected System.Web.UI.WebControls.TextBox tbContractTripPurpose;
		//		protected System.Web.UI.WebControls.TextBox tbReservedBudget;
		protected System.Web.UI.WebControls.TextBox tbNotSalesContractDescription;
		protected System.Web.UI.WebControls.RadioButtonList rbActivityInTrip;
		protected System.Web.UI.WebControls.RadioButtonList rbALInvitation;
		protected System.Web.UI.WebControls.TextBox tbRequestedDateFrom;
		protected System.Web.UI.WebControls.TextBox tbRequestedDateTo;
		protected System.Web.UI.WebControls.TextBox tbAlternateDateFrom;
		protected System.Web.UI.WebControls.TextBox tbAlternateDateTo;
		protected System.Web.UI.WebControls.TextBox tbTopic;
		protected System.Web.UI.WebControls.DataGrid dgALAttendee;
		protected System.Web.UI.WebControls.DataGrid dgContractInfo;
		protected System.Web.UI.WebControls.TextBox tbCustomerTeamHost;
		protected System.Web.UI.WebControls.TextBox tbCustomerOfficeTel;
		protected System.Web.UI.WebControls.TextBox tbCustomerFax;
		protected System.Web.UI.WebControls.TextBox tbCustomerEmail;
		protected System.Web.UI.WebControls.DropDownList ddlSalesBusinessUnit;
		protected System.Web.UI.WebControls.DropDownList ddlRegion;
		protected System.Web.UI.WebControls.RadioButtonList rbHotelRequired;
		protected System.Web.UI.WebControls.TextBox tbDatesRequiredFrom;
		protected System.Web.UI.WebControls.TextBox tbDatesRequiredTo;
		protected System.Web.UI.WebControls.TextBox tbPriceRangeFrom;
		protected System.Web.UI.WebControls.TextBox tbPriceRangeTo;
		protected System.Web.UI.WebControls.RadioButtonList rbTransportationRequired;
		protected System.Web.UI.WebControls.TextBox tbPreferEntertainment;
		protected System.Web.UI.WebControls.TextBox tbEntertainmentPriceRangeFrom;
		protected System.Web.UI.WebControls.TextBox tbEntertainmentPriceRangeTo;
		protected System.Web.UI.WebControls.RadioButtonList rbGiftNeed;
		protected System.Web.UI.WebControls.TextBox tbGiftPriceRangeFrom;
		protected System.Web.UI.WebControls.TextBox tbGiftPriceRangeTo;
		protected System.Web.UI.WebControls.RadioButtonList rbReceivedGift;
		protected System.Web.UI.WebControls.RadioButtonList rbInterpreterRequired;
		protected System.Web.UI.WebControls.RadioButtonList rbSimultaneousConsecutive;
		protected System.Web.UI.WebControls.RadioButtonList rbSpecialDialect;
		protected System.Web.UI.WebControls.DropDownList ddlPayingFor;
		protected System.Web.UI.WebControls.RadioButtonList rbDirectToProvider;
		protected System.Web.UI.WebControls.TextBox tbNotDirectReason;
		protected System.Web.UI.WebControls.TextBox tbEstimateCostPerPerson;
		protected System.Web.UI.WebControls.TextBox tbReason;
		protected System.Web.UI.WebControls.RadioButtonList rbCateringService;
		protected System.Web.UI.WebControls.TextBox tbCaterServiceExplain;
		protected System.Web.UI.WebControls.DataGrid dgCustomerList;
		protected System.Web.UI.WebControls.DataGrid dgCostCenter;
		protected System.Web.UI.WebControls.TextBox tbHotelPreferences;
		protected System.Web.UI.WebControls.TextBox tbPreferGift;
		protected System.Web.UI.WebControls.TextBox tbEstimateTotalCost;
		protected System.Web.UI.WebControls.TextBox tbRequestorName;
		protected System.Web.UI.WebControls.TextBox tbRequestOfficeTel;
		protected System.Web.UI.WebControls.TextBox tbRequestorMobile;
		protected System.Web.UI.WebControls.TextBox tbSomeoneTel;
		protected System.Web.UI.WebControls.TextBox tbDepartment;
		protected System.Web.UI.WebControls.RadioButtonList rbEntertainmentNeed;
		protected BEGDC.CC.Web.Control.UserSearchControl SearchStaff;
		protected System.Web.UI.WebControls.DropDownList ddlLegalEntity;

		protected System.Web.UI.WebControls.Label lbRequestorNameReadOnly;
		protected System.Web.UI.WebControls.Label lbRequestOfficeTelReadOnly;
		protected System.Web.UI.WebControls.Label lbRequestorMobileReadOnly;
		protected System.Web.UI.WebControls.Label lbSomeoneElseReadOnly;
		protected System.Web.UI.WebControls.Label lbSomeoneNameReadOnly;
		protected System.Web.UI.WebControls.Label lbSomeoneTelReadOnly;
		protected System.Web.UI.WebControls.Label lbSomeoneEmailReadOnly;
		protected System.Web.UI.WebControls.Label lbCustomerNameReadOnly;
		protected System.Web.UI.WebControls.Label lbIsFCPAReadOnly;
		protected System.Web.UI.WebControls.Label lbCustomerCountryReadOnly;
		protected System.Web.UI.WebControls.Label lbReviewGuideLineReadOnly;
		protected System.Web.UI.WebControls.Label lbPreferredLocationReadOnly;
		protected System.Web.UI.WebControls.Label lbOtherLocationReadOnly;
		protected System.Web.UI.WebControls.Label lbOtherCountryReadOnly;
		protected System.Web.UI.WebControls.Label lbGuestNumberReadOnly;
		protected System.Web.UI.WebControls.Label lbVisitObjectivesReadOnly;
		protected System.Web.UI.WebControls.Label lbPotentialRevenueReadOnly;
		protected System.Web.UI.WebControls.Label lbPotentialRevenueTimeReadOnly;
		protected System.Web.UI.WebControls.Label lbSaleStageReadOnly;
		protected System.Web.UI.WebControls.Label lbOutStandingRFPReadOnly;
		protected System.Web.UI.WebControls.Label lbSeneitiveIssuesReadOnly;
		protected System.Web.UI.WebControls.Label lbKeyMessageReadOnly;
		protected System.Web.UI.WebControls.Label lbCompanyProfileReadOnly;
		protected System.Web.UI.WebControls.Label lbAccountTypeReadOnly;
		protected System.Web.UI.WebControls.Label lbProposalNoReadOnly;
		protected System.Web.UI.WebControls.Label lbSalesContractReadOnly;
		protected System.Web.UI.WebControls.Label lbSalesContractSignedReadOnly;
		protected System.Web.UI.WebControls.Label lbContractDateReadOnly;
		protected System.Web.UI.WebControls.Label lbContractNoReadOnly;
		protected System.Web.UI.WebControls.Label lbContractProductsReadOnly;
		protected System.Web.UI.WebControls.Label lbContractTripPurposeReadOnly;
		protected System.Web.UI.WebControls.Label lbContractQuotasReadOnly;
		protected System.Web.UI.WebControls.Label lbUnitPriceReadOnly;
		protected System.Web.UI.WebControls.Label lbReservedBudgetReadOnly;
		protected System.Web.UI.WebControls.Label lbNotSalesContractDescriptionReadOnly;
		protected System.Web.UI.WebControls.Label lbActivityInTripReadOnly;
		protected System.Web.UI.WebControls.Label lbALInvitationReadOnly;
		protected System.Web.UI.WebControls.Label lbRequestedDateFromReadOnly;
		protected System.Web.UI.WebControls.Label lbRequestedDateToReadOnly;
		protected System.Web.UI.WebControls.Label lbAlternateDateFromReadOnly;
		protected System.Web.UI.WebControls.Label lbAlternateDateToReadOnly;
		protected System.Web.UI.WebControls.Label lbTopicReadOnly;
		protected System.Web.UI.WebControls.Label lbCustomerTeamHostReadOnly;
		protected System.Web.UI.WebControls.Label lbCustomerOfficeTelReadOnly;
		protected System.Web.UI.WebControls.Label lbCustomerFaxReadOnly;
		protected System.Web.UI.WebControls.Label lbCustomerEmailReadOnly;
		protected System.Web.UI.WebControls.Label lbSalesBusinessUnitReadOnly;
		protected System.Web.UI.WebControls.Label lbRegionReadOnly;
		protected System.Web.UI.WebControls.Label lbHotelRequiredReadOnly;
		protected System.Web.UI.WebControls.Label lbHotelPreferencesReadOnly;
		protected System.Web.UI.WebControls.Label lbDatesRequiredFromReadOnly;
		protected System.Web.UI.WebControls.Label lbDatesRequiredToReadOnly;
		protected System.Web.UI.WebControls.Label lbPriceRangeFromReadOnly;
		protected System.Web.UI.WebControls.Label lbPriceRangeToReadOnly;
		protected System.Web.UI.WebControls.Label lbTransportationRequiredReadOnly;
		protected System.Web.UI.WebControls.Label lbEntertainmentNeedReadOnly;
		protected System.Web.UI.WebControls.Label lbPreferEntertainmentReadOnly;
		protected System.Web.UI.WebControls.Label lbEntertainmentPriceRangeFromReadOnly;
		protected System.Web.UI.WebControls.Label lbEntertainmentPriceRangeToReadOnly;
		protected System.Web.UI.WebControls.Label lbGiftNeedReadOnly;
		protected System.Web.UI.WebControls.Label lbPreferGiftReadOnly;
		protected System.Web.UI.WebControls.Label lbGiftPriceRangeFromReadOnly;
		protected System.Web.UI.WebControls.Label lbGiftPriceRangeToReadOnly;
		protected System.Web.UI.WebControls.Label lbReceivedGiftReadOnly;
		protected System.Web.UI.WebControls.Label lbInterpreferRequiredReadOnly;
		protected System.Web.UI.WebControls.Label lbSimultaneousConsecutiveReadOnly;
		protected System.Web.UI.WebControls.Label lbSpecialDialectReadOnly;
		protected System.Web.UI.WebControls.Label lbPayingForReadOnly;
		protected System.Web.UI.WebControls.Label lbDirectToProviderReadOnly;
		protected System.Web.UI.WebControls.Label lbNotDirectReasonReadOnly;
		protected System.Web.UI.WebControls.Label lbEstimateTotalCostReadOnly;
		protected System.Web.UI.WebControls.Label lbEstimateCostPerPersonReadOnly;
		protected System.Web.UI.WebControls.Label lbReasonReadOnly;
		protected System.Web.UI.WebControls.Label lbCateringServiceReadOnly;
		protected System.Web.UI.WebControls.Label lbCaterServiceExplainReadOnly;
		protected System.Web.UI.WebControls.Label lbLegalEntity;
		protected System.Web.UI.WebControls.TextBox tbOperationFlag;
		protected System.Web.UI.WebControls.TextBox tbComment;
		protected System.Web.UI.WebControls.Label lbDepartmentReadOnly;
		protected System.Web.UI.WebControls.DropDownList ddlCATBranch;
		protected System.Web.UI.WebControls.DropDownList ddlAccount;
		protected System.Web.UI.WebControls.Label lbCATBranchReadOnly;
		protected System.Web.UI.WebControls.Label lbAccountReadOnly;
		protected System.Web.UI.WebControls.Label lbAccount;
		protected System.Web.UI.WebControls.Label lbContractSum;
		protected System.Web.UI.WebControls.Label lbCostSum;
		protected System.Web.UI.WebControls.Label lbAppNo;
		protected System.Web.UI.WebControls.Label lbSummaryReadOnly;
		protected System.Web.UI.HtmlControls.HtmlImage CustomerPaneImg;
		protected System.Web.UI.HtmlControls.HtmlImage ALPaneImg;
		protected System.Web.UI.HtmlControls.HtmlImage CostCenterPaneImg;
		protected System.Web.UI.HtmlControls.HtmlTableRow tr_Title;
		protected System.Web.UI.HtmlControls.HtmlTableRow tr_Button;
		protected System.Web.UI.HtmlControls.HtmlTableRow tr_knowledge;
		protected System.Web.UI.HtmlControls.HtmlTableRow tr_15_head;
		protected System.Web.UI.HtmlControls.HtmlTableRow tr_15_body;

		protected System.Web.UI.WebControls.TextBox Ctl_ArrivalDate;
		protected System.Web.UI.WebControls.Literal litScript;
		protected GDC.Utility.Web.ImgRequiredFieldValidator ContractDateRequired;
		protected GDC.Utility.Web.ImgRequiredFieldValidator RequestedDateFromRequired;
		protected GDC.Utility.Web.ImgRequiredFieldValidator RequestedDateToRequired;
		protected GDC.Utility.Web.ImgRequiredFieldValidator AlternateDateFromRequired;
		protected GDC.Utility.Web.ImgRequiredFieldValidator AlternateDateToRequired;
		protected GDC.Utility.Web.ImgRequiredFieldValidator DatesRequiredFromRequired;
		protected GDC.Utility.Web.ImgRequiredFieldValidator DatesRequiredToRequired;
		protected GDC.Utility.Web.ImgRequiredFieldValidator GuestNumberRequired;
		protected GDC.Utility.Web.ImgRangeValidator GuestNumberRange;
		protected GDC.Utility.Web.ImgRequiredFieldValidator PotentialRevenueRequired;
		protected GDC.Utility.Web.ImgRangeValidator PotentialRevenueRange;
		protected GDC.Utility.Web.ImgRequiredFieldValidator ContractQuotasRequired;
		protected GDC.Utility.Web.ImgRangeValidator ContractQuotasRange;
		protected GDC.Utility.Web.ImgRequiredFieldValidator UnitPriceRequired;
		protected GDC.Utility.Web.ImgRangeValidator UnitPriceRange;
		protected GDC.Utility.Web.ImgRequiredFieldValidator ReservedBudgetRequired;
		protected GDC.Utility.Web.ImgRangeValidator ReservedBudgetRange;
		protected GDC.Utility.Web.ImgRequiredFieldValidator PriceRangeFromRequired;
		protected GDC.Utility.Web.ImgRangeValidator PriceRangeFromRange;
		protected GDC.Utility.Web.ImgRequiredFieldValidator PriceRangeToRequired;
		protected GDC.Utility.Web.ImgRangeValidator PriceRangeToRange;
		protected GDC.Utility.Web.ImgRequiredFieldValidator EntertainmentPriceRangeFromRequired;
		protected GDC.Utility.Web.ImgRangeValidator EntertainmentPriceRangeFromRange;
		protected GDC.Utility.Web.ImgRequiredFieldValidator EntertainmentPriceRangeToRequired;
		protected GDC.Utility.Web.ImgRangeValidator EntertainmentPriceRangeToRange;
		protected GDC.Utility.Web.ImgRequiredFieldValidator GiftPriceRangeFromRequired;
		protected GDC.Utility.Web.ImgRangeValidator GiftPriceRangeFromRange;
		protected GDC.Utility.Web.ImgRequiredFieldValidator GiftPriceRangeToRequired;
		protected GDC.Utility.Web.ImgRangeValidator GiftPriceRangeToRange;
		protected GDC.Utility.Web.ImgRequiredFieldValidator EstimateTotalCostRequired;
		protected GDC.Utility.Web.ImgRangeValidator EstimateTotalCostRange;
		protected GDC.Utility.Web.ImgRequiredFieldValidator EstimateCostPerPersonRequired;
		protected GDC.Utility.Web.ImgRangeValidator EstimateCostPerPersonRange;
		//		protected System.Web.UI.HtmlControls.HtmlGenericControl img1;
		protected System.Web.UI.HtmlControls.HtmlGenericControl img2;
		protected System.Web.UI.HtmlControls.HtmlGenericControl img3;
		protected System.Web.UI.HtmlControls.HtmlGenericControl img4;
		protected System.Web.UI.HtmlControls.HtmlGenericControl img5;
		protected System.Web.UI.HtmlControls.HtmlGenericControl img6;
		protected System.Web.UI.HtmlControls.HtmlGenericControl img7;
		protected System.Web.UI.HtmlControls.HtmlImage ConrtractInfoPane;
		protected System.Web.UI.WebControls.DataGrid Btn_ContractDelete;
		protected System.Web.UI.HtmlControls.HtmlGenericControl span1;
		protected System.Web.UI.HtmlControls.HtmlGenericControl span2;
		protected System.Web.UI.HtmlControls.HtmlGenericControl span3;
		protected System.Web.UI.HtmlControls.HtmlGenericControl span4;
		////		protected System.Web.UI.HtmlControls.HtmlGenericControl span5;
		protected System.Web.UI.HtmlControls.HtmlGenericControl span6;
		protected System.Web.UI.HtmlControls.HtmlGenericControl span7;
		protected System.Web.UI.HtmlControls.HtmlGenericControl span8;
		//		protected System.Web.UI.HtmlControls.HtmlGenericControl span9;
		protected System.Web.UI.HtmlControls.HtmlGenericControl span10;
		//		protected System.Web.UI.HtmlControls.HtmlGenericControl span11;
		protected System.Web.UI.HtmlControls.HtmlGenericControl span12;
		//		protected System.Web.UI.HtmlControls.HtmlGenericControl span13;
		protected System.Web.UI.HtmlControls.HtmlGenericControl span14;
		protected System.Web.UI.HtmlControls.HtmlGenericControl span15;
		//		protected System.Web.UI.HtmlControls.HtmlGenericControl span16;
		protected System.Web.UI.WebControls.ImageButton btnCopy;
		protected System.Web.UI.WebControls.RadioButtonList rbDomesticOversea;
		protected System.Web.UI.WebControls.CheckBoxList cblDomesticOversea;
		protected System.Web.UI.WebControls.TextBox tbTravel;
		protected System.Web.UI.WebControls.Label lbTravelReadOnly;
		protected System.Web.UI.WebControls.Label lbDomesticReadonly;
		protected System.Web.UI.WebControls.TextBox tbHRID;
		protected System.Web.UI.WebControls.TextBox tbSomeoneMobile;
		protected System.Web.UI.WebControls.Label lbSomeoneHRIDReadOnly;
		protected System.Web.UI.WebControls.Label lbSomeoneMobileReadOnly;
		protected System.Web.UI.WebControls.TextBox tbReceivedGift;
		protected System.Web.UI.WebControls.Label lbReceivedGiftDescriptionReadOnly; 
		protected System.Web.UI.WebControls.Label lbEZVisitNoReadOnly;
		protected System.Web.UI.WebControls.Label lbLGDNoReadOnly;
		protected BEGDC.CC.Web.Common.StampCtrl stampCtrl1;
		protected BEGDC.CC.Web.UserControls.CV.CloseCtl closectl1;

		protected System.Web.UI.WebControls.TextBox tbReasonOfLocation;
		protected System.Web.UI.WebControls.Label lbReasonOfLocationReadOnly;

		private bool _isReadOnly = false;
		public bool isReadOnly
		{
			set
			{
				_isReadOnly = value;
			}
			get
			{
				return _isReadOnly;
			}
		}

		public bool IsKnowledgeShow
		{
			set
			{
				this.tr_knowledge.Visible = value;
			}
			get
			{
				return this.tr_knowledge.Visible ;
			}
		}
		private int CustomerID
		{
			set
			{
				ViewState["customerID"] = value;
			}
			get
			{
				if(ViewState["customerID"] == null)
					return 0;
				return Convert.ToInt32(ViewState["customerID"]);
			}
		}
		private int BusinessID
		{
			set
			{
				ViewState["businessID"] = value;
			}
			get
			{
				if(ViewState["businessID"] == null)
					return 0;
				return Convert.ToInt32(ViewState["businessID"]);
			}
		}
		private int TopicID
		{
			set
			{
				ViewState["topicID"] = value;
			}
			get
			{
				if(ViewState["topicID"] == null)
					return 0;
				return Convert.ToInt32(ViewState["topicID"]);
			}
		}
		private int SalesTeamID
		{
			set
			{
				ViewState["salesTeamID"] = value;
			}
			get
			{
				if(ViewState["salesTeamID"] == null)
					return 0;
				return Convert.ToInt32(ViewState["salesTeamID"]);
			}
		}
		private int LogistID
		{
			set
			{
				ViewState["logistID"] = value;
			}
			get
			{
				if(ViewState["logistID"] == null)
					return 0;
				return Convert.ToInt32(ViewState["logistID"]);
			}
		}
		private int PaymentID
		{
			set
			{
				ViewState["paymentID"] = value;
			}
			get
			{
				if(ViewState["paymentID"] == null)
					return 0;
				return Convert.ToInt32(ViewState["paymentID"]);
			}
		}

		#endregion

		#region variable define
		private bool IsQuery
		{
			get
			{
				string state = this.Request.QueryString["State"];
				if(state == null) return false;
				return state == SysDicItem.ProjectStatusFlag.QUERY;
			}
		}
		private bool IsView
		{
			get
			{
				string state = this.Request.QueryString["State"];
				if(state == null) return false;
				if(state == SysDicItem.ProjectStatusFlag.View || state == SysDicItem.ProjectStatusFlag.CANCEL
					|| state == SysDicItem.ProjectStatusFlag.Pending || state == SysDicItem.ProjectStatusFlag.End
					|| state == SysDicItem.ProjectStatusFlag.Participation)
					return true;
				else
					return false;
			}
		}
		protected string Step
		{
			get
			{
				IQuery queryService = BEGDC.Utility.Castle.AppContainer.Instance[BEGDC.CC.BL.Common.ServiceConst.QueryService] as IQuery;
				FlowInstance flowInstance = queryService.QueryFlowInstance( this.AppID );
				if( flowInstance == null )
					return WorkTransition.Draft;
				else
					return flowInstance.CurrentActiveStep.StepCode;
			}
		}
		protected string ApplicationNo
		{
			get
			{ 
				if( this.ViewState["ApplicationNo"] == null )
					return string.Empty;
				return this.ViewState["ApplicationNo"].ToString(); 
			}
			set{ this.ViewState["ApplicationNo"] = value; }
		}
		protected DateTime RequestDate
		{
			get
			{ 
				if( this.ViewState["RequestDate"] == null )
					return System.DateTime.Now;
				return (DateTime)this.ViewState["RequestDate"]; 
			}
			set{ this.ViewState["RequestDate"] = value; }
		}
		protected string DomesticList
		{
			get
			{ 
				if(ViewState["DomesticList"] == null)
					return string.Empty;
				return this.ViewState["DomesticList"].ToString(); 
			}
			set{ this.ViewState["DomesticList"] = value; }
		}
		protected string OverseaList
		{
			get
			{ 
				if(ViewState["OverseaList"] == null)
					return string.Empty;
				return this.ViewState["OverseaList"].ToString(); 
			}
			set{ this.ViewState["OverseaList"] = value; }
		}
		protected bool IsModify
		{
			get
			{ 
				if( this.ViewState["IsModify"] == null )
					return false;
				return (bool)this.ViewState["IsModify"]; 
			}
			set{ this.ViewState["IsModify"] = value; }
		}
		private const string DOMESTIC = "1";
		protected System.Web.UI.WebControls.Label lbIsSensitiveIssue;
		protected System.Web.UI.HtmlControls.HtmlInputHidden hiddenScrollHight;
		protected System.Web.UI.WebControls.Label lbDomesticOverseaReadOnly;
		protected System.Web.UI.WebControls.Label lblLegalEntity;
		private const string OVERSEA = "0";
		#endregion

		private void Page_Load(object sender, System.EventArgs e)
		{
			// Put user code to initialize the page here
			if(!Page.IsPostBack)
			{
				base.PreInitForm();
				Session[SessionFlag.AccompanySessionEZ] = null;
				Session[SessionFlag.CustomerSessionEZ] = null;
				Session[SessionFlag.ContractInfo] = null;
				Session[SessionFlag.CostCenter] = null;
				InitialDropDownList();

				this.btnReply.Attributes.Add("onclick", "javascript:OpenApplyReplyPane("+Request.QueryString["FlowID"]+");");
				this.btnSubmit.Attributes.Add("onclick", "javascript:OpenAssignmentPane();");

				BindApplication();
			}
			else
			{
				BindCustomerAttendee();
				BindALAttendee();
				BindCostCenter();
				BindContractInfo();
				
			}
			ButtonStatusSetting();

			this.litScript.Text = string.Empty;
			if(this.Access != null)
				ShowPanel(this.Access.IsReadOnly || this.IsView);
			else
				ShowPanel(true);

			if(this.IsModify)
				this.ShowModifyStatus();

			BindCloseControl();
		}

		private void ShowPanel(bool isReadOnly)
		{
			StringBuilder sb = new StringBuilder();
			sb.Append("<script>");
			if(isReadOnly)
			{
				sb.Append("_showpart2("+this.rbSomeoneElse.SelectedValue+");\n");
				sb.Append("_showHotelPart("+this.rbHotelRequired.SelectedValue+");\n");
				sb.Append("_ShowSensitiveIssue("+this.rbIsSensitiveIssue.SelectedValue+");\n");
				sb.Append("_ShowGiftPart("+this.rbGiftNeed.SelectedValue+");\n");
				sb.Append("_ShowReceivedGiftPart("+this.rbReceivedGift.SelectedValue+");\n");
				sb.Append("_ShowEnterment("+this.rbEntertainmentNeed.SelectedValue+");\n");
				sb.Append("_ShowContractPart("+this.rbSalesContract.SelectedValue+");\n");
				sb.Append("_ShowInterpreterPart("+this.rbInterpreterRequired.SelectedValue+");");
			}
			else
			{
				sb.Append("showpart2();\n");
				sb.Append("showHotelPart();\n");
				sb.Append("ShowSensitiveIssue();\n");
				sb.Append("ShowGiftPart();\n");
				sb.Append("ShowReceivedGiftPart();\n");
				sb.Append("ShowEnterment();\n");
				sb.Append("ShowContractPart();\n");
				sb.Append("ShowInterpreterPart();\n");
			}
			sb.Append("</script>");
			Page.RegisterStartupScript("EZCtrlForCO_Startup",sb.ToString());
		}

		#region Web Form Designer generated code
		override protected void OnInit(EventArgs e)
		{
			//
			// CODEGEN: This call is required by the ASP.NET Web Form Designer.
			//
			InitializeComponent();
			base.OnInit(e);
		}
		
		/// <summary>
		///		Required method for Designer support - do not modify
		///		the contents of this method with the code editor.
		/// </summary>
		private void InitializeComponent()
		{
			this.btnReply.Click += new System.Web.UI.ImageClickEventHandler(this.btnReply_Click);
			this.btnSave.Click += new System.Web.UI.ImageClickEventHandler(this.btnSave_Click);
			this.btnSubmit.Click += new System.Web.UI.ImageClickEventHandler(this.btnSubmit_Click);
			this.btnCopy.Click += new System.Web.UI.ImageClickEventHandler(this.btnCopy_Click);
			this.ddlCATBranch.SelectedIndexChanged += new System.EventHandler(this.ddlCATBranch_SelectedIndexChanged);
			this.rbSomeoneElse.SelectedIndexChanged += new System.EventHandler(this.rbSomeoneElse_SelectedIndexChanged);
			this.rbDomesticOversea.SelectedIndexChanged += new System.EventHandler(this.rbDomesticOversea_SelectedIndexChanged);
			this.dgContractInfo.DeleteCommand += new System.Web.UI.WebControls.DataGridCommandEventHandler(this.dgContractInfo_DeleteCommand);
			this.dgContractInfo.ItemDataBound += new System.Web.UI.WebControls.DataGridItemEventHandler(this.dgContractInfo_ItemDataBound);
			this.dgCustomerList.DeleteCommand += new System.Web.UI.WebControls.DataGridCommandEventHandler(this.dgCustomerList_DeleteCommand);
			this.dgCustomerList.ItemDataBound += new System.Web.UI.WebControls.DataGridItemEventHandler(this.dgCustomerList_ItemDataBound);
			this.dgALAttendee.DeleteCommand += new System.Web.UI.WebControls.DataGridCommandEventHandler(this.dgALAttendee_DeleteCommand);
			this.dgALAttendee.ItemDataBound += new System.Web.UI.WebControls.DataGridItemEventHandler(this.dgALAttendee_ItemDataBound);
			this.dgCostCenter.DeleteCommand += new System.Web.UI.WebControls.DataGridCommandEventHandler(this.dgCostCenter_DeleteCommand);
			this.dgCostCenter.ItemDataBound += new System.Web.UI.WebControls.DataGridItemEventHandler(this.dgCostCenter_ItemDataBound);
			this.Load += new System.EventHandler(this.Page_Load);

		}
		#endregion

		private void InitialDropDownList()
		{
			WebUtility.BuildDropDown(ddlPotentialRevenueTime,BEGDC.CC.BL.Common.DicType.POTENTIAL_REVENUE_TIMEFRAME,false,false);
			WebUtility.BuildDropDown(ddlSaleStage,BEGDC.CC.BL.Common.DicType.SALES_STAGE,false,false);
			WebUtility.BuildDropDown(ddlAccountType,BEGDC.CC.BL.Common.DicType.ACCOUNT_TYPE,false,false);
			WebUtility.BuildDropDown(ddlSalesBusinessUnit,BEGDC.CC.BL.Common.DicType.SALES_BUSINESS_UNIT,false,false);
			WebUtility.BuildDropDown(ddlRegion,BEGDC.CC.BL.Common.DicType.REGION,false,false);
			WebUtility.BuildDropDown(ddlPayingFor,BEGDC.CC.BL.Common.DicType.PAYER,false,false);
			WebUtility.BuildCheckBoxList(cblPreferredLocation,BEGDC.CC.BL.Common.DicType.VISITING_SITES);
			WebUtility.BuildCheckBoxList(this.cblDomesticOversea,BEGDC.CC.BL.Common.DicType.Domestic);
			
			BEGDC.CC.BL.Common.IUtility utility = AppContainer.Instance[ServiceConst.UtilityService] as BEGDC.CC.BL.Common.IUtility;
			BEGDC.CC.BL.Common.Query.IQuery queryService = AppContainer.Instance[ServiceConst.QueryService] as BEGDC.CC.BL.Common.Query.IQuery;
			DataTable catTable = queryService.GetDeptByTypeName( BEGDC.CC.BL.Common.DicType.CAT );
			DataTable branchTable = queryService.GetDeptByTypeName( BEGDC.CC.BL.Common.DicType.BRANCH );

			DataRow[] rows = catTable.Select();
			foreach( DataRow row in rows )
			{
				branchTable.ImportRow(row);
			}

			this.ddlCATBranch.DataSource = branchTable.DefaultView;
			this.ddlCATBranch.DataTextField = "DepartmentCode";
			this.ddlCATBranch.DataValueField = "DepartmentCode";
			this.ddlCATBranch.DataBind();
			this.ddlCATBranch.Items.Insert(this.ddlCATBranch.Items.Count,new System.Web.UI.WebControls.ListItem("Others","OTH"));
			
			//			IList CATList = utility.GetALLCATList();
			//			this.ddlAccount.DataSource = CATList;
			//			this.ddlAccount.DataValueField = "DepartmentCode";
			//			this.ddlAccount.DataTextField = "DepartmentCode";
			//			this.ddlAccount.DataBind();
			IList list = utility.BuildDicList( BEGDC.CC.BL.Common.DicType.ACCOUNT);

			ddlAccount.DataSource = list;
			ddlAccount.DataValueField = "DicItemKey";
			ddlAccount.DataTextField = "DicItemKey";
			ddlAccount.DataBind();

			//init legal entity
			this.ddlLegalEntity.DataSource = queryService.GetAllLegalEntity();
			this.ddlLegalEntity.DataTextField = "LegalEntityName";
			this.ddlLegalEntity.DataValueField = "LegalEntityID";
			this.ddlLegalEntity.DataBind();
		}

		private void BindApplication()
		{
			this.LoadApplication();
			this.tbRequestorName.Text = HttpContext.Current.User.Identity.Name;
			Employee emp = this.GetUser(HttpContext.Current.User.Identity.Name);
			this.lbDepartmentReadOnly.Text = emp.Department.DepartmentCode;
			this.tbDepartment.Text = emp.Department.Id.ToString() + "_" + emp.Department.DepartmentType.DicItemKey;

			if(this.AppID == 0)
			{
				BindCustomerAttendee();
				BindALAttendee();
				BindCostCenter();
				BindContractInfo();
				//				this.lbTitle.Text = "Edit Application";
				this.tr_knowledge.Visible = false;
				return;
			}
			IQuery queryService = AppContainer.Instance[ServiceConst.QueryService] as IQuery;
			CustomerInfo customer = queryService.GetCustomerInfo(this.AppID);
			BusinessPurpose business = queryService.GetBusinessPurposeInfo(this.AppID);                
			Topic topic = queryService.GetTopicInfo(this.AppID);
			SalesTeamInfo salesTeam = queryService.GetSalesTeamInfo(this.AppID);
			LogisticalInfo logist = queryService.GetLogisticalInfo(this.AppID);
			PaymentInfo payment = queryService.GetPaymentInfo(this.AppID);
			DataTable visitingSite = queryService.GetVisitingSite(this.AppID);
			BindApplicationData(visitingSite);
			BindCustomerInfoData(customer);
            BindBusinessPurposeData(business);
			BindTopicData(topic);
            BindSalesTeamData(salesTeam);
			BindLogisticalData(logist);
			BindPaymentData(payment);
			BindCustomerAttendee();
			BindALAttendee();
			BindCostCenter();
			BindContractInfo();

			
			//			else if(Request.QueryString["state"] != SysDicItem.ProjectStatusFlag.Reject && Request.QueryString["state"] != null
			//				&& Request.QueryString["state"] != string.Empty && Request.QueryString["state"] != SysDicItem.ProjectStatusFlag.CALLBACK)	
			//				this.tr_Title.Visible = false;
			//			
			//			if((!this.IsQuery) && (this.Step == WorkTransition.CV_Apply || this.Step == WorkTransition.CV_ReApply 
			//				|| this.Step == WorkTransition.Draft))
			//			{
			////				this.btnCopy.Visible = false;
			//				this.btnSave.Visible = true;
			//				this.btnSubmit.Visible = true;
			//				this.tr_Title.Visible = true;
			//			}
			//			else if(Request.QueryString["state"] != SysDicItem.ProjectStatusFlag.Reject && Request.QueryString["state"] != SysDicItem.ProjectStatusFlag.CALLBACK
			//				&& Request.QueryString["state"] != null && Request.QueryString["state"] != string.Empty)	
			//				this.tr_Title.Visible = false;
			//
			//			if(this.IsQuery)
			//				this.tr_Title.Visible = true;
		}

		private void BindApplicationData(DataTable site)
		{
			//			this.lbEZVisitNoReadOnly.Text = this.Application.EZVisitReqNo;
			//			this.lbLGDNoReadOnly.Text = this.Application.LGDNo;
			this.tbRequestorName.Text = this.Application.RequesterNameEN;
			Employee emp = this.GetUser(this.Application.RequesterNameEN);
			this.lbDepartmentReadOnly.Text = emp.Department.DepartmentCode;
			this.ddlLegalEntity.SelectedValue = this.Application.LegalEntity.Id.ToString();
			this.tbDepartment.Text = emp.Department.Id.ToString() + "_" + emp.Department.DepartmentType.DicItemKey;

			this.tbRequestorName.Text = this.Application.RequesterNameEN;
			this.tbRequestOfficeTel.Text = this.Application.RequesterOfficeTel;
			this.tbRequestorMobile.Text = this.Application.RequesterMobile;
			this.rbReviewGuideLine.SelectedValue = this.Application.IsReviewedGuideline? "1":"0";
			this.tbOtherLocation.Text = this.Application.OtherSite;
			this.tbReasonOfLocation.Text = this.Application.ReasonOfLocation;//yl
			this.tbOtherCountry.Text = this.Application.OtherCountry;
			if(this.Application.Summary + string.Empty != string.Empty)
				this.lbSummaryReadOnly.Text = this.Application.Summary;
			else
				this.tr_knowledge.Visible = false;
			if(this.Application.RequestedDateFrom != null)
				this.tbRequestedDateFrom.Text = ((DateTime)this.Application.RequestedDateFrom).ToString("MM/dd/yyyy");
			if(this.Application.RequestedDateTo != null)
				this.tbRequestedDateTo.Text = ((DateTime)this.Application.RequestedDateTo).ToString("MM/dd/yyyy");
			if(this.Application.AlternateDateFrom != null)
				this.tbAlternateDateFrom.Text = ((DateTime)this.Application.AlternateDateFrom).ToString("MM/dd/yyyy");
			if(this.Application.AlternateDateTo != null)
				this.tbAlternateDateTo.Text = ((DateTime)this.Application.AlternateDateTo).ToString("MM/dd/yyyy");
			this.lbDepartmentReadOnly.Text = this.Application.DepartmentName.DepartmentCode;
			this.ApplicationNo = this.Application.AppNo;
			if(this.ApplicationNo != string.Empty)
				this.lbAppNo.Text = "(" + this.ApplicationNo + ")";
			if(this.Application.RequestDate != null)
				this.RequestDate = (DateTime)this.Application.RequestDate;

			this.ddlAccount.SelectedValue = this.Application.Account;
			this.ddlCATBranch.SelectedValue = this.Application.AllDept;
			this.ddlCATBranch_SelectedIndexChanged(new object(), new System.EventArgs());

			this.rbSomeoneElse.SelectedValue = this.Application.ApplyForSomeoneElse? "1":"0";
			if(this.Application.ApplyForSomeoneElse)
			{
				this.SearchStaff.EmployeeName = this.Application.SomeoneElseNameEN;
				this.SearchStaff.EmployeeID = this.Application.SomeoneElseNo.Id;
				this.tbSomeoneTel.Text = this.Application.SomeoneElseTel;
				this.tbSomeoneEmail.Text = this.Application.SomeoneElseEmail;
				this.tbHRID.Text = this.Application.SomeoneElseHRID;
				this.tbSomeoneMobile.Text = this.Application.SomeoneElseMobil;
			}
			if(site != null && site.Rows.Count > 0)
			{
				for(int i=0; i<site.Rows.Count; i++)
					for(int j=0; j<this.cblPreferredLocation.Items.Count; j++)
					{
						if(site.Rows[i]["DicItemID"].ToString() == cblPreferredLocation.Items[j].Value)
							cblPreferredLocation.Items[j].Selected = true;
					}
			}

			if(this.Application.IsDomestic)
			{
				this.rbDomesticOversea.SelectedValue = DOMESTIC;
				if(this.Application.DomesticList != null)
					this.DomesticList = this.Application.DomesticList;
			}
			else
			{
				WebUtility.BuildCheckBoxList(this.cblDomesticOversea,BEGDC.CC.BL.Common.DicType.Oversea);
				this.rbDomesticOversea.SelectedValue = OVERSEA;
				if(this.Application.OverseaList != null)
					this.OverseaList = this.Application.OverseaList;
			}
			BindDomesticOversea();
		}

		private void BindDomesticOversea()
		{
			string[] temp = null;
			if(this.rbDomesticOversea.SelectedValue == DOMESTIC)
				temp = this.DomesticList.Split(',');
			else
				temp = this.OverseaList.Split(',');

			if(temp != null && temp.Length > 0)
			{
				for(int i=0; i<temp.Length; i++)
					for(int j=0; j<this.cblDomesticOversea.Items.Count; j++)
					{
						if(temp[i] == cblDomesticOversea.Items[j].Value)
							cblDomesticOversea.Items[j].Selected = true;
					}
			}
		}

		private void BindCustomerInfoData(CustomerInfo customer)
		{
			if(customer != null)
			{
                this.CustomerID = customer.Id;
				this.tbCustomerName.Text = customer.Company;
				this.rbIsFCPA.SelectedValue = customer.IsFCPA? "1":"0";
				this.tbCustomerCountry.Text = customer.Country;
				this.lbGuestNumberReadOnly.Text = customer.NumberOfPerson; 
				this.tbVisitObjectives.Text = customer.VisitObjective;
				this.tbPotentialRevenue.Text = customer.DecryptedRevenuePotential.ToString();
				this.ddlPotentialRevenueTime.SelectedValue = customer.PotentialRevenueTimeframe.ToString();
				this.ddlSaleStage.SelectedValue = customer.SalesStage.ToString();
				this.rbOutStandingRFP.SelectedValue = customer.IsInRFP? "1":"0"; 
				this.tbSensitiveIssues.Text = customer.IsThereSensitiveIssue;
				this.tbKeyMessage.Text = customer.IsThereKeyMessage;
				this.tbCompanyProfile.Text = customer.CompanyProfile;
                if(customer.AccountType != null)
				    this.ddlAccountType.SelectedValue = customer.AccountType.Id.ToString(); 
				this.tbProposalNo.Text = customer.ProposalNo;
				this.tbSensitiveIssues.Text = customer.IsThereSensitiveIssue;
				this.rbIsSensitiveIssue.SelectedValue = customer.IsSensitiveIssue? "1":"0";
			}
		}

		private void BindBusinessPurposeData(BusinessPurpose business)
		{
			if(business != null)
			{
                this.BusinessID = business.Id;
				this.rbSalesContract.SelectedValue = business.IsInSalesContract? "1":"0";
				this.rbSalesContractSigned.SelectedValue = business.IsContractSigned? "1":"0"; 
				//				this.tbContractDate.Text = ((DateTime)business.DateOfContract).ToString("MM/dd/yyyy");
				//				this.tbContractNo.Text = business.ContractNo;
				//				this.tbContractProducts.Text = business.ProductsSold;
				//				this.tbContractTripPurpose.Text = business.VisitPurposeInContract;
				//				this.tbContractQuotas.Text = business.Quotas.ToString();
				//				this.tbUnitPrice.Text = business.UnitPrice.ToString();
				this.tbNotSalesContractDescription.Text = business.Opportunities;
				this.rbActivityInTrip.SelectedValue = business.RecreationalActivity? "1":"0";
				this.rbALInvitation.SelectedValue = business.IsNeedInvitationLetter? "1":"0";
				//				this.tbReservedBudget.Text = business.Budget.ToString();
			}
		}

		private void BindTopicData(Topic topic)
		{
			if(topic != null)
			{
                this.TopicID = topic.Id;
				this.tbTopic.Text = topic.TopicName;
			}
		}

		private void BindSalesTeamData(SalesTeamInfo salesTeam)
		{
			if(salesTeam != null)
			{
                this.SalesTeamID = salesTeam.Id;
				this.tbCustomerTeamHost.Text = salesTeam.HostNameEN;
				this.tbCustomerOfficeTel.Text = salesTeam.OfficeTel;
				this.tbCustomerFax.Text = salesTeam.OfficeFax;
				this.tbCustomerEmail.Text = salesTeam.Email;
				this.ddlSalesBusinessUnit.SelectedValue = salesTeam.SalesBusinessUnit;
				this.ddlRegion.SelectedValue = salesTeam.Region;
			}
		}

		private void BindLogisticalData(LogisticalInfo logist)
		{
			if(logist != null)
			{
                this.LogistID = logist.Id;
				this.rbHotelRequired.SelectedValue = logist.IsNeedHotel? "1":"0";
				this.tbHotelPreferences.Text = logist.HotelPreferences;
				if(logist.DateRequiredFrom != null)
					this.tbDatesRequiredFrom.Text = ((DateTime)logist.DateRequiredFrom).ToString("MM/dd/yyyy");
				if(logist.DateRequiredTo != null)
					this.tbDatesRequiredTo.Text = ((DateTime)logist.DateRequiredTo).ToString("MM/dd/yyyy");
				this.tbPriceRangeFrom.Text = logist.DecryptedPriceFrom.ToString();
				this.tbPriceRangeTo.Text = logist.DecryptedPriceTo.ToString();
				this.rbTransportationRequired.SelectedValue = logist.IsNeedGroundTransportation? "1":"0";
				this.rbEntertainmentNeed.SelectedValue = logist.IsNeedEntertainment? "1":"0";
				this.tbPreferEntertainment.Text = logist.EntertainmentPreference;
				this.tbEntertainmentPriceRangeFrom.Text = logist.DecryptedEntertainmentPriceFrom.ToString();
				this.tbEntertainmentPriceRangeTo.Text = logist.DecryptedEntertainmentPriceTo.ToString();
				this.rbGiftNeed.SelectedValue = logist.IsNeedGift? "1":"0"; 
				this.tbPreferGift.Text = logist.GiftPreference;
				this.tbGiftPriceRangeFrom.Text = logist.DecryptedGiftPriceFrom.ToString();
				this.tbGiftPriceRangeTo.Text = logist.DecryptedGiftPriceTo.ToString();
				this.rbReceivedGift.SelectedValue = logist.IsReceivedALGiftBefore? "1":"0";
				this.rbInterpreterRequired.SelectedValue = logist.IsNeedInterpreter? "1":"0";
				this.rbSimultaneousConsecutive.SelectedValue = logist.InterpretionType.ToString();
				this.rbSpecialDialect.SelectedValue = logist.SpecialDialect;
				this.rbCateringService.SelectedValue = logist.IsNeedCatering? "1":"0";
				this.tbCaterServiceExplain.Text = logist.CateringDescription;
				this.tbTravel.Text = logist.TravelAgency;
			}
		}

		private void BindPaymentData(PaymentInfo payment)
		{
			if(payment != null)
			{
                this.PaymentID = payment.Id;
				this.ddlPayingFor.SelectedValue = payment.Payer.ToString();
				this.rbDirectToProvider.SelectedValue = payment.IsPayServiceProvider? "1":"0";
				this.tbNotDirectReason.Text = payment.NotDirectPayReasons;
				this.tbEstimateTotalCost.Text = payment.DecryptedEstimatedCustomerTotalCost.ToString();
				this.tbEstimateCostPerPerson.Text = payment.DecryptedEstimateCustomerdIndividualCost.ToString();
				this.tbReason.Text = payment.CustomerPerdiem;
			}
		}

		private void BindCustomerAttendee()
		{
			DataTable CustomerDataTable = null;
			object SessCustomerAttendee = Session[SessionFlag.CustomerSessionEZ];
			if(SessCustomerAttendee!=null)
			{
				CustomerDataTable = (DataTable)SessCustomerAttendee;
			}
			else
			{
				if(this.CustomerID > 0)
				{
					IQuery queryService = AppContainer.Instance[ServiceConst.QueryService] as IQuery;
					CustomerDataTable = queryService.GetCustomerAttendeeList(this.CustomerID);
				}
				if(CustomerDataTable!=null&&CustomerDataTable.Rows.Count>0)
				{
					Session[SessionFlag.CustomerSessionEZ] = CustomerDataTable;
				}
				else
				{
					CustomerDataTable = new DataTable();
					CustomerDataTable.Columns.Add(new DataColumn("Id", typeof(System.String)));
					CustomerDataTable.Columns.Add(new DataColumn("Name", typeof(System.String)));
					CustomerDataTable.Columns.Add(new DataColumn("Company", typeof(System.String)));
					CustomerDataTable.Columns.Add(new DataColumn("Title", typeof(System.String)));
					CustomerDataTable.Columns.Add(new DataColumn("NameCN", typeof(System.String)));
					CustomerDataTable.Columns.Add(new DataColumn("CompanyEN", typeof(System.String)));
					CustomerDataTable.Columns.Add(new DataColumn("TitleEN", typeof(System.String)));
					CustomerDataTable.Columns.Add(new DataColumn("Responsibility", typeof(System.String)));
					CustomerDataTable.Columns.Add(new DataColumn("Affects", typeof(System.String)));
					CustomerDataTable.Columns.Add(new DataColumn("ResponsibilityID", typeof(System.String)));
					CustomerDataTable.Columns.Add(new DataColumn("AffectsID", typeof(System.String)));
					CustomerDataTable.Columns.Add(new DataColumn("Remark", typeof(System.String)));
					CustomerDataTable.Columns.Add(new DataColumn("IsExisted", typeof(System.String)));
					Session[SessionFlag.CustomerSessionEZ] = CustomerDataTable;
				}
			}
			if (CustomerDataTable.Select("IsExisted='"+BEGDC.CC.BL.Common.CISFlag.NotExisted+"'").Length > 0)
			{
				this.Lb_CISWarning.Visible = true;
			}
			else
			{
				this.Lb_CISWarning.Visible = false;
			}
			this.dgCustomerList.DataSource = this.SetRowID(CustomerDataTable);
			this.dgCustomerList.DataBind();
			this.lbGuestNumberReadOnly.Text = CustomerDataTable.Rows.Count.ToString();
		}

		private void BindALAttendee()
		{
			DataTable AccompanyingAttendee = null;
			if(Session[SessionFlag.AccompanySessionEZ] != null)
			{
				AccompanyingAttendee = (DataTable)Session[SessionFlag.AccompanySessionEZ];
			}
			else
			{
				if(this.AppID > 0)
				{
					ICR crService = AppContainer.Instance[ServiceConst.CRService] as ICR;
					AccompanyingAttendee = crService.GetAccompanyingAttendeeList(this.AppID);
				}
				if(AccompanyingAttendee == null || AccompanyingAttendee.Rows.Count == 0)
				{
					AccompanyingAttendee = new DataTable();
					AccompanyingAttendee.Columns.Add(new DataColumn("Id", typeof(System.String)));
					AccompanyingAttendee.Columns.Add(new DataColumn("EmployeeId", typeof(System.String)));
					AccompanyingAttendee.Columns.Add(new DataColumn("Name", typeof(System.String)));
					AccompanyingAttendee.Columns.Add(new DataColumn("Title", typeof(System.String)));
				}
				Session[SessionFlag.AccompanySessionEZ] = AccompanyingAttendee;
			}
			this.dgALAttendee.DataSource = this.SetRowID(AccompanyingAttendee);
			this.dgALAttendee.DataBind();
		}

		private void BindCostCenter()
		{
			DataTable CostCenter = null;
			if(Session[SessionFlag.CostCenter] != null)
			{
				CostCenter = (DataTable)Session[SessionFlag.CostCenter];
			}
			else
			{
				if(this.PaymentID > 0)
				{
					IQuery queryService = AppContainer.Instance[ServiceConst.QueryService] as IQuery;
					CostCenter = queryService.GetCostCenter(this.PaymentID);
				}
				if(CostCenter == null || CostCenter.Rows.Count == 0)
				{
					CostCenter = new DataTable();
					CostCenter.Columns.Add(new DataColumn("Id", typeof(System.String)));
					CostCenter.Columns.Add(new DataColumn("CostCenterCode", typeof(System.String)));
					CostCenter.Columns.Add(new DataColumn("Cost", typeof(System.String)));
					CostCenter.Columns.Add(new DataColumn("ActualCost", typeof(System.String)));
				}
				Session[SessionFlag.CostCenter] = CostCenter;
			}
			this.dgCostCenter.DataSource = this.SetRowID(CostCenter);
			this.dgCostCenter.DataBind();

			this.lbCostSum.Text = this.CalculateCostSum();

			if(!(this.Step == WorkTransition.CV_Close || this.Step == WorkTransition.End))
				dgCostCenter.Columns[3].Visible = false;
		}

		private void BindContractInfo()
		{
			DataTable ContractInfo = null;
			if(Session[SessionFlag.ContractInfo] != null)
			{
				ContractInfo = (DataTable)Session[SessionFlag.ContractInfo];
			}
			else
			{
				if(this.AppID > 0)
				{
					IQuery queryService = AppContainer.Instance[ServiceConst.QueryService] as IQuery;
					ContractInfo = SetRowID(queryService.QueryContractInfoByAppId(this.AppID));
				}
				if(ContractInfo == null || ContractInfo.Rows.Count == 0)
				{
					ContractInfo = new DataTable();
					ContractInfo.Columns.Add(new DataColumn("RowId", typeof(System.String)));
					ContractInfo.Columns.Add(new DataColumn("DateOfContract", typeof(System.DateTime)));
					ContractInfo.Columns.Add(new DataColumn("ContractNo", typeof(System.String)));
					ContractInfo.Columns.Add(new DataColumn("ProducstSold", typeof(System.String)));
					ContractInfo.Columns.Add(new DataColumn("VisitPurposeInContract", typeof(System.String)));
					ContractInfo.Columns.Add(new DataColumn("Quotas", typeof(System.Int32)));
					ContractInfo.Columns.Add(new DataColumn("UnitPrice", typeof(System.Decimal)));
					ContractInfo.Columns.Add(new DataColumn("Budget", typeof(System.Decimal)));
				}
				Session[SessionFlag.ContractInfo] = ContractInfo;
			}
			this.dgContractInfo.DataSource = this.SetRowID(ContractInfo);
			this.dgContractInfo.DataBind();

			this.lbContractSum.Text = CalculateSum();
		}

		private DataTable SetRowID(DataTable table)
		{
			if(table != null && table.Rows.Count >0)
				for(int i=1; i<=table.Rows.Count; i++)
				{
					table.Rows[i-1][0] = i.ToString();
				}
			return table;
		}

		private void BindReadOnlyStatus()
		{
			this.btnCopy.Visible = false;
			this.btnSave.Visible = false;
			this.btnSubmit.Visible = false;
			this.ALPaneImg.Visible = false;
			this.CustomerPaneImg.Visible = false;
			this.CostCenterPaneImg.Visible = false;
			this.ConrtractInfoPane.Visible = false;
			this.img2.Visible = false;
			this.img3.Visible = false;
			this.img3.Visible = false;
			this.img4.Visible = false;
			this.img5.Visible = false;
			this.img6.Visible = false;
			this.img7.Visible = false;
			this.span1.Visible = false;
			this.span2.Visible = false;
			this.span3.Visible = false;
			this.span4.Visible = false;
			//			this.span5.Visible = false;
			this.span6.Visible = false;
			this.span7.Visible = false;
			this.span8.Visible = false;
			//			this.span9.Visible = false;
			this.span10.Visible = false;
			//			this.span11.Visible = false;
			this.span12.Visible = false;
			//			this.span13.Visible = false;
			this.span14.Visible = false;
			this.span15.Visible = false;
			//			this.span16.Visible = false;
			
			// Application
			//			this.lbEZVisitNoReadOnly.Visible = true;
			//			this.lbLGDNoReadOnly.Visible = true;
			this.tbRequestorName.Visible = false;
			this.lbRequestorNameReadOnly.Text = this.tbRequestorName.Text;
			this.tbRequestOfficeTel.Visible = false;
			this.lbRequestOfficeTelReadOnly.Text = this.tbRequestOfficeTel.Text;
			this.tbRequestorMobile.Visible = false;
			this.lbRequestorMobileReadOnly.Text = this.tbRequestorMobile.Text;
			this.rbReviewGuideLine.Visible = false;
			this.lbReviewGuideLineReadOnly.Text = this.rbReviewGuideLine.SelectedItem.Text;
			this.tbOtherLocation.Visible = false;
			this.lbOtherLocationReadOnly.Text = this.tbOtherLocation.Text;
			//yl
			this.tbReasonOfLocation.Visible = false;
			this.lbReasonOfLocationReadOnly.Text = this.tbReasonOfLocation.Text;
			this.tbOtherCountry.Visible = false;
			this.lbOtherCountryReadOnly.Text = this.tbOtherCountry.Text;
			this.tbRequestedDateFrom.Visible = false;
			this.lbRequestedDateFromReadOnly.Text = this.tbRequestedDateFrom.Text;
			this.tbRequestedDateTo.Visible = false;
			this.lbRequestedDateToReadOnly.Text = this.tbRequestedDateTo.Text;
			this.tbAlternateDateFrom.Visible = false;
			this.lbAlternateDateFromReadOnly.Text = this.tbAlternateDateFrom.Text;
			this.tbAlternateDateTo.Visible = false;
			this.lbAlternateDateToReadOnly.Text = this.tbAlternateDateTo.Text;
			this.rbSomeoneElse.Visible = false;
			this.lbSomeoneElseReadOnly.Text = this.rbSomeoneElse.SelectedItem.Text;
			this.SearchStaff.Visible = false;
			this.lbSomeoneNameReadOnly.Text = this.SearchStaff.EmployeeName;
			this.tbSomeoneTel.Visible = false;
			this.lbSomeoneTelReadOnly.Text = this.tbSomeoneTel.Text;
			this.tbSomeoneEmail.Visible = false;
			this.lbSomeoneEmailReadOnly.Text = this.tbSomeoneEmail.Text;
			this.tbHRID.Visible = false;
			this.lbSomeoneHRIDReadOnly.Text = this.tbHRID.Text;
			this.tbSomeoneMobile.Visible = false;
			this.lbSomeoneMobileReadOnly.Text = this.tbSomeoneMobile.Text;
			this.cblPreferredLocation.Visible = false;
			for(int i=0; i<this.cblPreferredLocation.Items.Count; i++)
				if(cblPreferredLocation.Items[i].Selected)
					this.lbPreferredLocationReadOnly.Text += cblPreferredLocation.Items[i].Text + ",";
			string temp = this.lbPreferredLocationReadOnly.Text;
			if(temp != string.Empty)
				this.lbPreferredLocationReadOnly.Text = temp.Substring(0, temp.Length -1);
			this.ddlCATBranch.Visible = false;
			this.lbCATBranchReadOnly.Text = this.ddlCATBranch.SelectedItem.Text;
			this.ddlAccount.Visible = false;
			this.lbAccountReadOnly.Text = this.ddlAccount.SelectedItem.Text;
			this.cblDomesticOversea.Visible = false;
			for(int i=0; i<this.cblDomesticOversea.Items.Count; i++)
				if(cblDomesticOversea.Items[i].Selected)
					this.lbDomesticReadonly.Text += cblDomesticOversea.Items[i].Text + ",";
			this.rbDomesticOversea.Visible = false;
			this.lbDomesticOverseaReadOnly.Text = this.rbDomesticOversea.SelectedItem.Text;
			if(this.Application.EZVisitReqNo != string.Empty)
				this.lbEZVisitNoReadOnly.Text = "EZVisitNo: "+this.Application.EZVisitReqNo;
			//			if(this.Application.LGDNo != string.Empty)
			//				this.lbLGDNoReadOnly.Text = "LGD No: "+this.Application.LGDNo;
			this.ddlLegalEntity.Visible = false;
			this.lbLegalEntity.Text = this.ddlLegalEntity.SelectedItem.Text;
			
			// Customer
			this.tbCustomerName.Visible = false;
			this.lbCustomerNameReadOnly.Text = this.tbCustomerName.Text;
			this.rbIsFCPA.Visible = false;
			this.lbIsFCPAReadOnly.Text = this.rbIsFCPA.SelectedItem.Text;
			this.tbCustomerCountry.Visible = false;
			this.lbCustomerCountryReadOnly.Text = this.tbCustomerCountry.Text;
			//			this.tbGuestNumber.Visible = false;
			//			this.lbGuestNumberReadOnly.Text = this.tbGuestNumber.Text;
			this.tbVisitObjectives.Visible = false;
			this.lbVisitObjectivesReadOnly.Text = this.tbVisitObjectives.Text;
			this.tbPotentialRevenue.Visible = false;
			this.lbPotentialRevenueReadOnly.Text = this.tbPotentialRevenue.Text;
			this.ddlPotentialRevenueTime.Visible = false;
			this.lbPotentialRevenueTimeReadOnly.Text = this.ddlPotentialRevenueTime.SelectedItem.Text;
			this.ddlSaleStage.Visible = false;
			this.lbSaleStageReadOnly.Text = this.ddlSaleStage.SelectedItem.Text;
			this.rbOutStandingRFP.Visible = false;
			this.lbOutStandingRFPReadOnly.Text = this.rbOutStandingRFP.SelectedItem.Text;
			this.tbSensitiveIssues.Visible = false;
			this.lbSeneitiveIssuesReadOnly.Text = this.tbSensitiveIssues.Text;
			this.tbKeyMessage.Visible = false;
			this.lbKeyMessageReadOnly.Text = this.tbKeyMessage.Text;
			this.tbCompanyProfile.Visible = false;
			this.lbCompanyProfileReadOnly.Text = this.tbCompanyProfile.Text;
			this.ddlAccountType.Visible = false;
			this.lbAccountTypeReadOnly.Text = this.ddlAccountType.SelectedItem.Text;
			this.tbProposalNo.Visible = false;
			this.lbProposalNoReadOnly.Text = this.tbProposalNo.Text;
			this.rbIsSensitiveIssue.Visible = false;
			this.lbSeneitiveIssuesReadOnly.Text = this.tbSensitiveIssues.Text;

			// Business Purpose
			this.rbSalesContract.Visible = false;
			this.lbSalesContractReadOnly.Text = this.rbSalesContract.SelectedItem.Text;
			this.rbSalesContractSigned.Visible = false;
			this.lbSalesContractSignedReadOnly.Text = this.rbSalesContractSigned.SelectedItem.Text;
			this.tbNotSalesContractDescription.Visible = false;
			this.lbNotSalesContractDescriptionReadOnly.Text = this.tbNotSalesContractDescription.Text;
			this.rbActivityInTrip.Visible = false;
			this.lbActivityInTripReadOnly.Text = this.rbActivityInTrip.SelectedItem.Text;
			this.rbALInvitation.Visible = false;
			this.lbALInvitationReadOnly.Text = this.rbALInvitation.SelectedItem.Text;
			//			this.tbReservedBudget.Visible = false;
			//			this.lbReservedBudgetReadOnly.Text = this.tbReservedBudget.Text;

			// Topic
			this.tbTopic.Visible = false;
			this.lbTopicReadOnly.Text = this.tbTopic.Text;

			// Sales Team
			this.tbCustomerTeamHost.Visible = false;
			this.lbCustomerTeamHostReadOnly.Text = this.tbCustomerTeamHost.Text;
			this.tbCustomerOfficeTel.Visible = false;
			this.lbCustomerOfficeTelReadOnly.Text = this.tbCustomerOfficeTel.Text;
			this.tbCustomerFax.Visible = false;
			this.lbCustomerFaxReadOnly.Text = this.tbCustomerFax.Text;
			this.tbCustomerEmail.Visible = false;
			this.lbCustomerEmailReadOnly.Text = this.tbCustomerEmail.Text;
			this.ddlSalesBusinessUnit.Visible = false;
			this.lbSalesBusinessUnitReadOnly.Text = this.ddlSalesBusinessUnit.SelectedItem.Text;
			this.ddlRegion.Visible = false;
			this.lbRegionReadOnly.Text = this.ddlRegion.SelectedItem.Text;

			// LogisticalInfo
			this.rbHotelRequired.Visible = false;
			this.lbHotelRequiredReadOnly.Text = this.rbHotelRequired.SelectedItem.Text;
			this.tbHotelPreferences.Visible = false;
			this.lbHotelPreferencesReadOnly.Text = this.tbHotelPreferences.Text;
			this.tbDatesRequiredFrom.Visible = false;
			this.lbDatesRequiredFromReadOnly.Text = this.tbDatesRequiredFrom.Text;
			this.tbDatesRequiredTo.Visible = false;
			this.lbDatesRequiredToReadOnly.Text = this.tbDatesRequiredTo.Text;
			this.tbPriceRangeFrom.Visible = false;
			this.lbPriceRangeFromReadOnly.Text = this.tbPriceRangeFrom.Text;
			this.tbPriceRangeTo.Visible = false;
			this.lbPriceRangeToReadOnly.Text = this.tbPriceRangeTo.Text;
			this.rbTransportationRequired.Visible = false;
			this.lbTransportationRequiredReadOnly.Text = this.rbTransportationRequired.SelectedItem.Text;
			this.rbEntertainmentNeed.Visible = false;
			this.lbEntertainmentNeedReadOnly.Text = this.rbEntertainmentNeed.SelectedItem.Text;
			this.tbPreferEntertainment.Visible = false;
			this.lbPreferEntertainmentReadOnly.Text = this.tbPreferEntertainment.Text;
			this.tbEntertainmentPriceRangeFrom.Visible = false;
			this.lbEntertainmentPriceRangeFromReadOnly.Text = this.tbEntertainmentPriceRangeFrom.Text;
			this.tbEntertainmentPriceRangeTo.Visible = false;
			this.lbEntertainmentPriceRangeToReadOnly.Text = this.tbEntertainmentPriceRangeTo.Text;
			this.rbGiftNeed.Visible = false;
			this.lbGiftNeedReadOnly.Text = this.rbGiftNeed.SelectedItem.Text;
			this.tbPreferGift.Visible = false;
			this.lbPreferGiftReadOnly.Text = this.tbPreferGift.Text;
			this.tbGiftPriceRangeFrom.Visible = false;
			this.lbGiftPriceRangeFromReadOnly.Text = this.tbGiftPriceRangeFrom.Text;
			this.tbGiftPriceRangeTo.Visible = false;
			this.lbGiftPriceRangeToReadOnly.Text = this.tbGiftPriceRangeTo.Text;
			this.rbReceivedGift.Visible = false;
			this.lbReceivedGiftReadOnly.Text = this.rbReceivedGift.SelectedItem.Text;
			this.rbInterpreterRequired.Visible = false;
			this.lbInterpreferRequiredReadOnly.Text = this.rbInterpreterRequired.SelectedItem.Text;
			this.rbSimultaneousConsecutive.Visible = false;
			this.lbSimultaneousConsecutiveReadOnly.Text = this.rbSimultaneousConsecutive.SelectedItem.Text;
			this.rbSpecialDialect.Visible = false;
			this.lbSpecialDialectReadOnly.Text = this.rbSpecialDialect.SelectedItem.Text;
			this.rbCateringService.Visible = false;
			this.lbCateringServiceReadOnly.Text = this.rbCateringService.SelectedItem.Text;
			this.tbCaterServiceExplain.Visible = false;
			this.lbCaterServiceExplainReadOnly.Text = this.tbCaterServiceExplain.Text;
			this.tbTravel.Visible = false;
			this.lbTravelReadOnly.Text = this.tbTravel.Text;
			this.tbReceivedGift.Visible = false;
			this.lbReceivedGiftDescriptionReadOnly.Text = this.tbReceivedGift.Text;

			// Payment Info
			this.ddlPayingFor.Visible = false;
			this.lbPayingForReadOnly.Text = this.ddlPayingFor.SelectedItem.Text;
			this.rbDirectToProvider.Visible = false;
			this.lbDirectToProviderReadOnly.Text = this.rbDirectToProvider.SelectedItem.Text;
			this.tbNotDirectReason.Visible = false;
			this.lbNotDirectReasonReadOnly.Text = this.tbNotDirectReason.Text;
			this.tbEstimateTotalCost.Visible = false;
			this.lbEstimateTotalCostReadOnly.Text = this.tbEstimateTotalCost.Text;
			this.tbEstimateCostPerPerson.Visible = false;
			this.lbEstimateCostPerPersonReadOnly.Text = this.tbEstimateCostPerPerson.Text;
			this.tbReason.Visible = false;
			this.lbReasonReadOnly.Text = this.tbReason.Text;

			this.dgCustomerList.Columns[6].Visible = false;
			this.dgALAttendee.Columns[3].Visible = false;
			this.dgCostCenter.Columns[4].Visible = false;
			this.dgContractInfo.Columns[8].Visible = false;
			//			this.closectl1.SetReadOnly();
		}

		private void BuildApplication(ref Application app, ref CustomerInfo customer, ref BusinessPurpose business, 
			ref Topic topic, ref SalesTeamInfo salesTeam, ref LogisticalInfo logist, ref PaymentInfo payment, 
			ref IList customerAttendee, ref IList alAttendee, ref IList site, ref IList cost, ref IList contract)
		{
			app.Id = this.AppID;
			app.EZVisitReqNo = string.Empty;
			app.LGDNo = string.Empty;
			app.ApplicationType = WorkflowTypes.CV;
			app.RequesterOfficeTel = this.tbRequestOfficeTel.Text.Trim();
			app.RequesterMobile = this.tbRequestorMobile.Text.Trim();
			app.IsReviewedGuideline = this.rbReviewGuideLine.SelectedValue == "1";
			app.OtherSite = this.tbOtherLocation.Text.Trim();
			app.ReasonOfLocation = this.tbReasonOfLocation.Text.Trim();//yl
			app.OtherCountry = this.tbOtherCountry.Text.Trim();
			app.RequesterNameEN = this.tbRequestorName.Text.Trim();
			if(this.tbRequestedDateFrom.Text != string.Empty)
				app.RequestedDateFrom = Convert.ToDateTime(this.tbRequestedDateFrom.Text);
			if(this.tbRequestedDateTo.Text != string.Empty)
				app.RequestedDateTo = Convert.ToDateTime(this.tbRequestedDateTo.Text);
			if(this.tbAlternateDateFrom.Text != string.Empty)
				app.AlternateDateFrom = Convert.ToDateTime(this.tbAlternateDateFrom.Text);
			if(this.tbAlternateDateTo.Text != string.Empty)
				app.AlternateDateTo = Convert.ToDateTime(this.tbAlternateDateTo.Text);
			app.AllDept = this.ddlCATBranch.SelectedValue;
			app.Account = this.ddlAccount.SelectedValue;
			app.AppNo = this.ApplicationNo;
			app.RequestDate = this.RequestDate;

			IQuery query = AppContainer.Instance[ServiceConst.QueryService] as IQuery;
			// Apply for someone else
			if(this.rbSomeoneElse.SelectedValue == "1")
			{
				app.DepartmentName = this.GetUser(this.SearchStaff.EmployeeName).Department;
				
				app.ApplyForSomeoneElse = true;
				app.SomeoneElseNo = new Employee();
				app.SomeoneElseNo.Id = this.SearchStaff.EmployeeID;
				app.SomeoneElseNameEN = this.SearchStaff.EmployeeName;
				app.SomeoneElseTel = this.tbSomeoneTel.Text.Trim();
				app.SomeoneElseEmail = this.tbSomeoneEmail.Text.Trim();
				app.SomeoneElseHRID = this.tbHRID.Text.Trim();
				app.SomeoneElseMobil = this.tbSomeoneMobile.Text.Trim();
			}
			else
			{
				app.DepartmentName = this.GetUser(app.RequesterNameEN).Department;
			}
			app.LegalEntity = new LegalEntity();
			app.LegalEntity.Id = Convert.ToInt32(this.ddlLegalEntity.SelectedValue);
			app.DepartmentType = app.DepartmentName.DepartmentType;
			
			IUser userService = AppContainer.Instance[ServiceConst.UserService] as IUser;
			app.RequesterNo = userService.GetUser(app.RequesterNameEN);

			string temp = string.Empty;
			string list = string.Empty;
			for(int i=0;i<this.cblDomesticOversea.Items.Count;i++)
			{
				if(cblDomesticOversea.Items[i].Selected)
				{
					temp += cblDomesticOversea.Items[i].Value + ",";
					list += cblDomesticOversea.Items[i].Text + ",";
				}
			}
			if(temp.Length > 0)
				temp = temp.TrimEnd(',');
			if(list.Length > 0)
				list = list.TrimEnd(',');

			if(this.rbDomesticOversea.SelectedValue == DOMESTIC)
			{
				app.IsDomestic = true;
				app.DomesticList = temp;
				app.OverseaList = string.Empty;
			}
			else
			{
				app.IsDomestic = false;
				app.OverseaList = temp;
				app.DomesticList = string.Empty;
			}
			

			// Customer Info
			customer.Id = this.CustomerID;
			customer.Company = this.tbCustomerName.Text.Trim();
			customer.IsFCPA = this.rbIsFCPA.SelectedValue == "1";
			customer.Country = this.tbCustomerCountry.Text.Trim();
			customer.NumberOfPerson = this.lbGuestNumberReadOnly.Text.Trim();
			customer.VisitObjective = this.tbVisitObjectives.Text.Trim();
			if(WebUtility.IsNumber(this.tbPotentialRevenue.Text))
				customer.DecryptedRevenuePotential = Convert.ToDecimal(this.tbPotentialRevenue.Text);
			customer.PotentialRevenueTimeframe = Convert.ToInt32(this.ddlPotentialRevenueTime.SelectedValue);
			customer.SalesStage = Convert.ToInt32(this.ddlSaleStage.SelectedValue);
			customer.IsInRFP = this.rbOutStandingRFP.SelectedValue == "1";
			customer.IsThereSensitiveIssue = this.tbSensitiveIssues.Text.Trim();
			customer.IsThereKeyMessage = this.tbKeyMessage.Text.Trim();
			customer.CompanyProfile = this.tbCompanyProfile.Text.Trim();
			customer.AccountType = new DicItem();
			customer.AccountType.Id = Convert.ToInt32(this.ddlAccountType.SelectedValue);
			customer.ProposalNo = this.tbProposalNo.Text.Trim();
			customer.IsSensitiveIssue = this.rbIsSensitiveIssue.SelectedValue == "1";
			customer.IsThereSensitiveIssue = this.tbSensitiveIssues.Text.Trim();
			customer.Venue = list;

			// BusinessPurpose
			business.Id = this.BusinessID;
			business.IsInSalesContract = this.rbSalesContract.SelectedValue == "1";
			business.IsContractSigned = this.rbSalesContractSigned.SelectedValue == "1";
			business.RecreationalActivity = this.rbActivityInTrip.SelectedValue == "1";
			business.IsNeedInvitationLetter = this.rbALInvitation.SelectedValue == "1";
			business.Opportunities = this.tbNotSalesContractDescription.Text.Trim();

			// Topic 
			topic.Id = this.TopicID;
			topic.TopicName = this.tbTopic.Text.Trim();

			// SalesTeam
			salesTeam.Id = this.SalesTeamID;
			salesTeam.HostNameEN = this.tbCustomerTeamHost.Text.Trim();
			salesTeam.OfficeTel = this.tbCustomerOfficeTel.Text.Trim();
			salesTeam.OfficeFax = this.tbCustomerFax.Text.Trim();
			salesTeam.Email = this.tbCustomerEmail.Text.Trim();
			salesTeam.SalesBusinessUnit = this.ddlSalesBusinessUnit.SelectedValue;
			salesTeam.Region = this.ddlRegion.SelectedValue;

			// LogisticalInfo
			logist.Id = this.LogistID;
			logist.IsNeedHotel = this.rbHotelRequired.SelectedValue == "1";
			logist.HotelPreferences = this.tbHotelPreferences.Text;
			if(this.tbDatesRequiredFrom.Text != string.Empty)
				logist.DateRequiredFrom = Convert.ToDateTime(this.tbDatesRequiredFrom.Text);
			if(this.tbDatesRequiredTo.Text != string.Empty)
				logist.DateRequiredTo = Convert.ToDateTime(this.tbDatesRequiredTo.Text);
			if(WebUtility.IsNumber(this.tbPriceRangeFrom.Text))
				logist.DecryptedPriceFrom = Convert.ToDecimal(this.tbPriceRangeFrom.Text);
			if(WebUtility.IsNumber(this.tbPriceRangeTo.Text))
				logist.DecryptedPriceTo = Convert.ToDecimal(this.tbPriceRangeTo.Text);
			logist.IsNeedGroundTransportation = this.rbTransportationRequired.SelectedValue == "1";
			logist.IsNeedEntertainment = this.rbEntertainmentNeed.SelectedValue == "1";
			logist.EntertainmentPreference = this.tbPreferEntertainment.Text.Trim();
			if(WebUtility.IsNumber(this.tbEntertainmentPriceRangeFrom.Text))
				logist.DecryptedEntertainmentPriceFrom = Convert.ToDecimal(this.tbEntertainmentPriceRangeFrom.Text);
			if(WebUtility.IsNumber(this.tbEntertainmentPriceRangeTo.Text))
				logist.DecryptedEntertainmentPriceTo = Convert.ToDecimal(this.tbEntertainmentPriceRangeTo.Text);
			logist.IsNeedGift = this.rbGiftNeed.SelectedValue == "1";
			logist.GiftPreference = this.tbPreferGift.Text;
			if(WebUtility.IsNumber(this.tbGiftPriceRangeFrom.Text))
				logist.DecryptedGiftPriceFrom = Convert.ToDecimal(this.tbGiftPriceRangeFrom.Text);
			if(WebUtility.IsNumber(this.tbGiftPriceRangeTo.Text))
				logist.DecryptedGiftPriceTo = Convert.ToDecimal(this.tbGiftPriceRangeTo.Text);
			logist.IsReceivedALGiftBefore = this.rbReceivedGift.SelectedValue == "1";
			logist.IsNeedInterpreter = this.rbInterpreterRequired.SelectedValue == "1";
			logist.InterpretionType = Convert.ToInt32(this.rbSimultaneousConsecutive.SelectedValue);
			logist.SpecialDialect = this.rbSpecialDialect.SelectedValue;
			logist.IsNeedCatering = this.rbCateringService.SelectedValue == "1";
			logist.CateringDescription = this.tbCaterServiceExplain.Text.Trim();
			logist.TravelAgency = this.tbTravel.Text.Trim();

			// Payment Info
			payment.Id = this.PaymentID;
			payment.Payer = Convert.ToInt32(this.ddlPayingFor.SelectedValue);
			payment.IsPayServiceProvider = this.rbDirectToProvider.SelectedValue == "1";
			payment.NotDirectPayReasons = this.tbNotDirectReason.Text.Trim();
			if(this.tbEstimateTotalCost.Text != string.Empty)
				payment.DecryptedEstimatedCustomerTotalCost = Convert.ToDecimal(this.tbEstimateTotalCost.Text);
			if(this.tbEstimateCostPerPerson.Text != string.Empty)
				payment.DecryptedEstimateCustomerdIndividualCost = Convert.ToDecimal(this.tbEstimateCostPerPerson.Text);
			payment.CustomerPerdiem = this.tbReason.Text.Trim();

			// site info
			for(int i=0;i<this.cblPreferredLocation.Items.Count;i++)
			{
				if(cblPreferredLocation.Items[i].Selected)
				{
					AppVisitingSite appSite = new AppVisitingSite();
					appSite.Site = new DicItem();
					appSite.Site.Id = Convert.ToInt32(cblPreferredLocation.Items[i].Value);

					site.Add(appSite);
				}
			}

			// Customer Attendee Info
			DataTable table = (DataTable)this.dgCustomerList.DataSource;
			if(table != null && table.Rows.Count > 0)
			{
				for(int i=0;i<table.Rows.Count;i++)
				{
					CustomerAttendee cus = new CustomerAttendee();
					cus.NameEN = table.Rows[i]["Name"].ToString();
					cus.Title = table.Rows[i]["Title"].ToString();
					cus.Company = table.Rows[i]["Company"].ToString();		
					cus.NameCN = table.Rows[i]["NameCN"].ToString();
					cus.TitleEN = table.Rows[i]["TitleEN"].ToString();
					cus.CompanyEN = table.Rows[i]["CompanyEN"].ToString();		
					cus.Responsibility = new DicItem();
					cus.Responsibility.Id =	Convert.ToInt32(table.Rows[i]["ResponsibilityID"]);
					cus.Affects = new DicItem();
					cus.Affects.Id = Convert.ToInt32(table.Rows[i]["AffectsID"]);
					cus.IsAttended = true;

					cus.Remark = table.Rows[i]["Remark"].ToString();
					cus.IsExisted = Convert.ToInt32(table.Rows[i]["IsExisted"]);

					customerAttendee.Add(cus);
				}
			}

			// AL Attendee Info
			table = (DataTable)this.dgALAttendee.DataSource;
			if(table != null && table.Rows.Count > 0)
			{
				for(int i=0;i<table.Rows.Count;i++)
				{
					ALAttendee al = new ALAttendee();
					al.EmployeeId = new Employee();
					al.EmployeeId.Id = table.Rows[i]["EmployeeId"].ToString();
					al.Title = table.Rows[i]["Title"].ToString();
			
					alAttendee.Add(al);
				}
			}

			// Cost Center Info
			table = (DataTable)this.dgCostCenter.DataSource;
			if(table != null && table.Rows.Count > 0)
			{
				for(int i=0;i<table.Rows.Count;i++)
				{
					CostCenterRelatedCost co = new CostCenterRelatedCost();
					co.CostCenterCode = table.Rows[i]["CostCenterCode"].ToString();
					co.DecryptedCost = Convert.ToDecimal(table.Rows[i]["Cost"]);
					co.CostType = CostType.Budget;
			
					cost.Add(co);
				}
			}

			// Contract Info
			table = (DataTable)this.dgContractInfo.DataSource;
			if(table != null && table.Rows.Count > 0)
			{
				for(int i=0;i<table.Rows.Count;i++)
				{
					ContractInfo ci = new ContractInfo();
					ci.DateOfContract = Convert.ToDateTime(table.Rows[i]["DateOfContract"]);
					ci.ContractNo = table.Rows[i]["ContractNo"].ToString();
					ci.ProducstSold = table.Rows[i]["ProducstSold"].ToString();
					ci.VisitPurposeInContract = table.Rows[i]["VisitPurposeInContract"].ToString();
					ci.Quotas = Convert.ToInt32(table.Rows[i]["Quotas"]);
					ci.UnitPrice = Convert.ToDecimal(table.Rows[i]["UnitPrice"]);
					ci.Budget = Convert.ToDecimal(table.Rows[i]["Budget"]);
			
					contract.Add(ci);
				}
			}
		}

		private void btnSave_Click(object sender, System.Web.UI.ImageClickEventArgs e)
		{
			Save(true);
		}
		public void Save(bool isAlert)
		{
			try
			{
				ICV cvService = AppContainer.Instance[ServiceConst.CVService] as ICV;
			
				Application app = new Application();
				CustomerInfo customer = new CustomerInfo();
				BusinessPurpose business = new BusinessPurpose();
				Topic topic = new Topic();
				SalesTeamInfo salesTeam = new SalesTeamInfo();
				LogisticalInfo logist = new LogisticalInfo();
				PaymentInfo payment = new PaymentInfo();
				IList customerAttendee = new ArrayList();
				IList alAttendee = new ArrayList();
				IList site = new ArrayList();
				IList cost = new ArrayList();
				IList contract = new ArrayList();

				BuildApplication(ref app, ref customer, ref business, ref topic, ref salesTeam, ref logist, ref payment, 
					ref customerAttendee, ref alAttendee, ref site, ref cost, ref contract);
				cvService.Save(app, customer, business, topic, salesTeam, logist, payment, customerAttendee, alAttendee, site, cost, contract);
				this.AppID = app.Id;
				this.CustomerID = customer.Id;
				this.BusinessID = business.Id;
				this.TopicID = topic.Id;
				this.SalesTeamID = salesTeam.Id;
				this.LogistID = logist.Id;
				this.PaymentID = payment.Id;
				this.ApplicationNo = app.AppNo;
				this.ctrlExport.Visible=true;

				if(isAlert)
				{
					Session["AppID"] = app.Id;
					//					string url;
					//					litScript.Visible = true;
					//
					//					string alertFlag = Request.Form["tbURL"];
					//					if(alertFlag == string.Empty)
					//						litScript.Text = "<script>VbAlert('Operation finished successfully.')</script>";
					//					if(this.Request.Url.AbsoluteUri.IndexOf("AppID") == -1)
					//					{
					//						url = this.Request.Url.AbsoluteUri;
					//						if(Request.Form["tbSwitchTab"] == string.Empty)
					//							url = url.Substring(0, url.Length-9) + "&AppID="+app.Id+"&Type=App";
					//						else
					//							url = url.Substring(0, url.Length-9) + "&AppID="+app.Id+"&Type="+Request.Form["tbSwitchTab"].ToString();
					//						litScript.Text += "<script language='javascript'>";
					//						litScript.Text += "window.location.replace('"+url+"');";
					//						litScript.Text += "</script>";
					//					}	
				
					string url = string.Empty + Request.Form["tbURL"];
					string script = "<script>";
					if(url == string.Empty)
						script += "VBAlert('" + BEGDC.CC.Resource.SystemMessage.CM001 + "');";
					if(url != string.Empty)
					{
						if(url.IndexOf("AppID") == -1)
							url = url.Substring(0,url.IndexOf("?")+1)+"AppID="+app.Id+"&"+url.Substring(url.IndexOf("?")+1);
						script += "window.location.href='"+url+"'";
					}
					else
					{
						url = Request.Url.AbsoluteUri;
						if(url.ToUpper().IndexOf("APPID") == -1)
						{
							url = url.Substring(0,url.IndexOf("?")+1)+"AppID="+app.Id+"&"+url.Substring(url.IndexOf("?")+1);
							script += "window.location.href='"+url+"'";
						}
					}
					script += "</script>";

					Page.RegisterClientScriptBlock("",script);
					this.btnCopy.Visible = true;
				}
				//				this.SetAppID(app.Id);
			}
			catch(Exception ex)
			{
				Page.RegisterClientScriptBlock("","<script>alert('" + BEGDC.CC.Resource.SystemMessage.CV002 + "');</script>");
			}
		}
		private void btnSubmit_Click(object sender, System.Web.UI.ImageClickEventArgs e)
		{
			try
			{
				string msg;
				
				IList attTypes = new ArrayList();
				attTypes.Add(BEGDC.CC.BL.CCFlow.AttachmentType.AGENDA);
				attTypes.Add(BEGDC.CC.BL.CCFlow.AttachmentType.BUDGET);
				if(this.rbGiftNeed.SelectedValue == "1")
					attTypes.Add(BEGDC.CC.BL.CCFlow.AttachmentType.GIFT);
				if(this.rbSalesContract.SelectedValue == "1")
					attTypes.Add(BEGDC.CC.BL.CCFlow.AttachmentType.CONTRACT);
				if(this.rbALInvitation.SelectedValue == "1")
					attTypes.Add(BEGDC.CC.BL.CCFlow.AttachmentType.VISA);
				msg = BEGDC.CC.BL.CCFlow.AttachmentService.GetMissedAttachmentMessage( this.AppID, attTypes );
				
				if( msg!="" && msg!=string.Empty)
				{
					Page.RegisterClientScriptBlock("","<script>alert('" + msg + "');</script>");
					return;
				}
				ICV cvService = AppContainer.Instance[ServiceConst.CVService] as ICV;
				
				Application app = new Application();
				CustomerInfo customer = new CustomerInfo();
				BusinessPurpose business = new BusinessPurpose();
				Topic topic = new Topic();
				SalesTeamInfo salesTeam = new SalesTeamInfo();
				LogisticalInfo logist = new LogisticalInfo();
				PaymentInfo payment = new PaymentInfo();
				IList customerAttendee = new ArrayList();
				IList alAttendee = new ArrayList();
				IList site = new ArrayList();
				IList cost = new ArrayList();
				IList contract = new ArrayList();

				string catdirector = string.Empty;
				if(Session["CATDirector"] != null)
					catdirector = Session["CATDirector"].ToString();
				BuildApplication(ref app, ref customer, ref business, ref topic, ref salesTeam, ref logist, ref payment, 
					ref customerAttendee, ref alAttendee, ref site, ref cost, ref contract);
				if(app.AppNo.IndexOf("-D") >= 0)
					app.AppNo = string.Empty;
				
				if( customerAttendee == null || customerAttendee.Count == 0 )
				{
					Page.RegisterClientScriptBlock("","<script>alert('At least one customer should be specified.');</script>");
					return;
				}
				cvService.Request(app, customer, business, topic, salesTeam, logist, payment, customerAttendee, alAttendee, site, cost, contract, catdirector);
			
				Page.RegisterClientScriptBlock("","<script>VbAlert('" + BEGDC.CC.Resource.SystemMessage.CV001 + "');</script><script>window.close();</script>");
			}
			catch
			{
				Page.RegisterClientScriptBlock("","<script>alert('" + BEGDC.CC.Resource.SystemMessage.CV002 + "');</script>");
			}
		}

		private void dgCustomerList_ItemDataBound(object sender, System.Web.UI.WebControls.DataGridItemEventArgs e)
		{
			if ((e.Item.ItemType == ListItemType.Item) || (e.Item.ItemType == ListItemType.AlternatingItem))
			{
				ImageButton Btn_Edit = (ImageButton) e.Item.Cells[5].FindControl("Btn_Edit");
				string ItemId = e.Item.Cells[0].Text.ToString();
				Btn_Edit.Attributes.Add("onclick", "OpenCustomerPane('"+ItemId+"');");
				Btn_Edit.Attributes.Add("check", "false");

				ImageButton ld = (ImageButton)e.Item.Cells[6].FindControl("Btn_Delete");
				if(ld != null)
				{
					ld.Attributes.Add("onclick","On_Submit();");
					ld.Attributes.Add("check", "false");
				}

				string IsExisted = e.Item.Cells[7].Text.ToString();
				if(IsExisted==BEGDC.CC.BL.Common.CISFlag.NotExisted)
				{
					System.Web.UI.WebControls.Image WarningImg = (System.Web.UI.WebControls.Image) e.Item.Cells[8].FindControl("CISWarning");
					WarningImg.Visible = true;
				}
			}
		}
		
		private void dgALAttendee_ItemDataBound(object sender, System.Web.UI.WebControls.DataGridItemEventArgs e)
		{
			if ((e.Item.ItemType == ListItemType.Item) || (e.Item.ItemType == ListItemType.AlternatingItem))
			{
				ImageButton Btn_Edit = (ImageButton) e.Item.Cells[3].FindControl("Btn_ALEdit");
				string ItemId = e.Item.Cells[0].Text.ToString();
				Btn_Edit.Attributes.Add("onclick", "OpenALAttendeePane('"+ItemId+"');");
				Btn_Edit.Attributes.Add("check", "false");

				ImageButton ld = (ImageButton)e.Item.Cells[3].FindControl("Btn_ALDelete");
				if(ld != null)
				{
					ld.Attributes.Add("onclick","On_Submit();");
					ld.Attributes.Add("check", "false");
				}
			}
		}

		
		private void dgCostCenter_ItemDataBound(object sender, System.Web.UI.WebControls.DataGridItemEventArgs e)
		{
			if ((e.Item.ItemType == ListItemType.Item) || (e.Item.ItemType == ListItemType.AlternatingItem))
			{
				ImageButton Btn_Edit = (ImageButton) e.Item.Cells[3].FindControl("Btn_CostEdit");
				string ItemId = e.Item.Cells[0].Text.ToString();
				Btn_Edit.Attributes.Add("onclick", "OpenCostCenterPane('"+ItemId+"');");

				ImageButton ld = (ImageButton)e.Item.Cells[3].FindControl("Btn_CostDelete");
				if(ld != null)
				{
					ld.Attributes.Add("onclick","On_Submit();");
				}
			}
		}

		private void dgContractInfo_ItemDataBound(object sender, System.Web.UI.WebControls.DataGridItemEventArgs e)
		{
			if ((e.Item.ItemType == ListItemType.Item) || (e.Item.ItemType == ListItemType.AlternatingItem))
			{
				ImageButton Btn_Edit = (ImageButton) e.Item.Cells[8].FindControl("Btn_ContractEdit");
				string ItemId = e.Item.Cells[0].Text.ToString();
				Btn_Edit.Attributes.Add("onclick", "OpenContractPane('"+ItemId+"');");
				Btn_Edit.Attributes.Add("check", "false");
				
				ImageButton ld = (ImageButton)e.Item.Cells[8].FindControl("Btn_ContractDelete");
				if(ld != null)
				{
					ld.Attributes.Add("onclick","On_Submit();");
					ld.Attributes.Add("check", "false");
				}
			}
		}

		private void rbSomeoneElse_SelectedIndexChanged(object sender, System.EventArgs e)
		{
			this.litScript.Visible = true;
			if(this.rbSomeoneElse.SelectedValue == "1")
				this.litScript.Text = "<script>showpart2(1);</script>";
			else
				this.litScript.Text = "<script>showpart2(0);</script>";
		}

		private Employee GetUser(string name)
		{
			IUser userService = AppContainer.Instance[ServiceConst.UserService] as IUser;
			return userService.GetUser(name);
		}

		private void ControlStatusSetting(Accessibility access )
		{
			if( access == Accessibility.Readonly )
			{
				this.DisableChildrenControls(this);
			}
		}

		private void dgContractInfo_DeleteCommand(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e)
		{
			try
			{
				if(Request.Form["cbDel"] == null || Request.Form["cbDel"] == "1")
				{
					return;
				}

				int rowid = Convert.ToInt32(e.Item.Cells[0].Text);
			
				DataTable contractInfo = (DataTable)Session[SessionFlag.ContractInfo];
				DataRow contractRow = contractInfo.Rows[rowid-1];
				contractInfo.Rows.Remove(contractRow);
				this.BindContractInfo();
			}
			catch
			{	
			}
		}

		private void dgCustomerList_DeleteCommand(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e)
		{
			try
			{
				if(Request.Form["cbDel"] == null || Request.Form["cbDel"] == "1")
				{
					return;
				}

				int rowid = Convert.ToInt32(e.Item.Cells[0].Text);
			
				DataTable contractInfo = (DataTable)Session[SessionFlag.CustomerSessionEZ];
				DataRow contractRow = contractInfo.Rows[rowid-1];
				contractInfo.Rows.Remove(contractRow);
				this.BindCustomerAttendee();
			}
			catch
			{	
			}
		}

		private void dgALAttendee_DeleteCommand(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e)
		{
			try
			{
				if(Request.Form["cbDel"] == null || Request.Form["cbDel"] == "1")
				{
					return;
				}

				int rowid = Convert.ToInt32(e.Item.Cells[0].Text);
			
				DataTable contractInfo = (DataTable)Session[SessionFlag.AccompanySessionEZ];
				DataRow contractRow = contractInfo.Rows[rowid-1];
				contractInfo.Rows.Remove(contractRow);
				this.BindALAttendee();
			}
			catch
			{	
			}
		}

		private void dgCostCenter_DeleteCommand(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e)
		{
			try
			{
				if(Request.Form["cbDel"] == null || Request.Form["cbDel"] == "1")
				{
					return;
				}

				int rowid = Convert.ToInt32(e.Item.Cells[0].Text);
			
				DataTable contractInfo = (DataTable)Session[SessionFlag.CostCenter];
				DataRow contractRow = contractInfo.Rows[rowid-1];
				contractInfo.Rows.Remove(contractRow);
				this.BindCostCenter();
			}
			catch
			{	
			}
		}

		private void btnCopy_Click(object sender, System.Web.UI.ImageClickEventArgs e)
		{
			try
			{
				ICV cvService = AppContainer.Instance[ServiceConst.CVService] as ICV;
				cvService.CopyCV(this.AppID);
				//				ICV cvService = AppContainer.Instance[ServiceConst.CVService] as ICV;
				//			
				//				Application app = new Application();
				//				CustomerInfo customer = new CustomerInfo();
				//				BusinessPurpose business = new BusinessPurpose();
				//				Topic topic = new Topic();
				//				SalesTeamInfo salesTeam = new SalesTeamInfo();
				//				LogisticalInfo logist = new LogisticalInfo();
				//				PaymentInfo payment = new PaymentInfo();
				//				IList customerAttendee = new ArrayList();
				//				IList alAttendee = new ArrayList();
				//				IList site = new ArrayList();
				//				IList cost = new ArrayList();
				//				IList contract = new ArrayList();
				//
				//				BuildApplication(ref app, ref customer, ref business, ref topic, ref salesTeam, ref logist, ref payment, 
				//					ref customerAttendee, ref alAttendee, ref site, ref cost, ref contract);
				//				app.Id = 0;
				//				customer.Id = 0;
				//				business.Id = 0;
				//				topic.Id = 0;
				//				salesTeam.Id = 0;
				//				logist.Id = 0;
				//				payment.Id = 0;
				//
				//				app.AppNo = string.Empty;
				//				cvService.Save(app, customer, business, topic, salesTeam, logist, payment, customerAttendee, alAttendee, site, cost, contract);
				//Page.RegisterClientScriptBlock("","<script>VBAlert('" + BEGDC.CC.Resource.SystemMessage.CV001 + "');</script>");
			}
			catch
			{
				Page.RegisterClientScriptBlock("","<script>alert('" + BEGDC.CC.Resource.SystemMessage.CV002 + "');</script>");
			}

			Page.RegisterClientScriptBlock("","<script>VBAlert('" + BEGDC.CC.Resource.SystemMessage.CM004 + "');</script>");
		}

		private void rbDomesticOversea_SelectedIndexChanged(object sender, System.EventArgs e)
		{
			string temp = string.Empty;
			for(int i=0;i<this.cblDomesticOversea.Items.Count;i++)
			{
				if(cblDomesticOversea.Items[i].Selected)
				{
					temp += cblDomesticOversea.Items[i].Value + ",";
				}
			}
			if(temp.Length > 0)
				temp = temp.TrimEnd(',');

			if(this.rbDomesticOversea.SelectedValue == DOMESTIC)
			{
				WebUtility.BuildCheckBoxList(this.cblDomesticOversea,BEGDC.CC.BL.Common.DicType.Domestic);
				this.OverseaList = temp;
			}
			else
			{
				WebUtility.BuildCheckBoxList(this.cblDomesticOversea,BEGDC.CC.BL.Common.DicType.Oversea);
				this.DomesticList = temp;
			}

			BindDomesticOversea();
		}
		
		public void DisableCATBranch()
		{
			this.ddlCATBranch.Enabled = false;
			this.ddlAccount.Enabled = false;
		}

		public void ShowModifyStatus()
		{
			this.ALPaneImg.Visible = true;
			this.CustomerPaneImg.Visible = true;
			this.tbRequestedDateFrom.Visible = true;
			this.tbRequestedDateTo.Visible = true;
			this.lbRequestedDateFromReadOnly.Visible = false;
			this.lbRequestedDateToReadOnly.Visible = false;
			img2.Visible = true;
			img3.Visible = true;
			this.dgCustomerList.Columns[6].Visible = true;
			this.dgALAttendee.Columns[3].Visible = true;

			this.IsModify = true;
		}

		public void EndModifyStatus()
		{
			this.ALPaneImg.Visible = false;
			this.CustomerPaneImg.Visible = false;
			this.tbRequestedDateFrom.Visible = false;
			this.tbRequestedDateTo.Visible = false;
			this.lbRequestedDateFromReadOnly.Text = this.tbRequestedDateFrom.Text;
			this.lbRequestedDateToReadOnly.Text = this.tbRequestedDateTo.Text;
			this.lbRequestedDateFromReadOnly.Visible = true;
			this.lbRequestedDateToReadOnly.Visible = true;
			img2.Visible = false;
			img3.Visible = false;
			this.dgCustomerList.Columns[6].Visible = false;
			this.dgALAttendee.Columns[3].Visible = false;

			this.IsModify = false;
		}

		protected override void ButtonStatusSetting()
		{			
			if( this.Access == null )
			{
				tr_Title.Visible = false;
				BindReadOnlyStatus();
				return;
			}

			this.btnSubmit.Visible = this.Access.IsButtonVisible(CVTransitionList.Submit);
			this.btnSave.Visible = this.Access.IsButtonVisible(CVTransitionList.Save);
			this.btnReply.Visible = this.Access.IsButtonVisible(CVTransitionList.Reply);
			this.btnCopy.Visible = this.Access.IsButtonVisible(CVTransitionList.Copy);

			//			if( ((this.Access.IsHideAllButton || this.Access.IsReadOnly) || (this.Step != WorkTransition.Draft
			//				&& this.Step != WorkTransition.CV_Apply && this.Step != WorkTransition.CV_ReApply)) && !this.IsQuery)
			if( (this.Access.IsHideAllButton) || (this.Access.IsReadOnly && !this.IsQuery) || (this.Step != WorkTransition.Draft
				&& this.Step != WorkTransition.CV_Apply && this.Step != WorkTransition.CV_ReApply))
			{
				tr_Title.Visible = false;
			}
			if((this.Access.IsReadOnly || this.IsView))
				BindReadOnlyStatus();
			if(this.IsQuery)
				this.DisableCATBranch();
		}

		private void SetAppID(int appid)
		{
			this.Access.AppId = appid;
		}

		private void ddlCATBranch_SelectedIndexChanged(object sender, System.EventArgs e)
		{
			if(this.ddlCATBranch.SelectedValue.StartsWith("B"))
			{
				this.lbAccount.Visible = true;
				this.ddlAccount.Visible = true;
			}
			else
			{
				this.lbAccount.Visible = false;
				this.ddlAccount.Visible = false;
			}
		}

		private void btnReply_Click(object sender, System.Web.UI.ImageClickEventArgs e)
		{
			try
			{
				ICV cvService = AppContainer.Instance[ServiceConst.CVService] as ICV;
				cvService.ReplyQuery(Convert.ToInt64(Request.QueryString["FlowID"]), WebUtility.DeCodeString(Server, tbComment.Text));
				Page.RegisterClientScriptBlock("","<script>VBAlert('" + BEGDC.CC.Resource.SystemMessage.CV001 + "');window.close();</script>");
			}
			catch
			{
				Page.RegisterClientScriptBlock("","<script>alert('" + BEGDC.CC.Resource.SystemMessage.CV002 + "');</script>");
			}
		}


		private string CalculateSum()
		{
			decimal sum = 0;
			DataTable table = (DataTable)this.dgContractInfo.DataSource;
			if(table != null)
			{
				for(int i=0; i<table.Rows.Count; i++)
				{
					sum += Convert.ToDecimal(table.Rows[i]["Budget"]);
				}
			}

			return sum.ToString("0.00");
		}

		private string CalculateCostSum()
		{
			decimal sum = 0;
			DataTable table = (DataTable)this.dgCostCenter.DataSource;
			if(table != null)
			{
				for(int i=0; i<table.Rows.Count; i++)
				{
					sum += Convert.ToDecimal(table.Rows[i]["Cost"]);
				}
			}

			return sum.ToString("0.00");
		}

		public void BindCloseControl()
		{
			this.closectl1.BindApplication();
			this.closectl1.SetKBInvisible();
		}

		public void ShowBuHead()
		{
			this.tr_15_body.Visible = true;
			this.tr_15_head.Visible = true;
		}
		
	}
}
